Lightweights and Their Graphics

Invoking getGraphics() on a lightweight component returns a copy of the Graphics for the lightweight's heavyweight container. Since lightweights are rendered in their (heavyweight) container's window, they have no Graphics of their own.

Figure 19-5 shows an applet with a simple heavyweight component.

Figure 19-5. A Simple Heavyweight Component

The applet is listed in Example 19-7.

Example 19-7. A Heavyweight Component
 import java.applet.Applet; import java.awt.*; public class TestApplet extends Applet { public void ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.