A Simple Lightweight Component
Lightweight components are extremely simple to implement—a lightweight component is lightweight because by virtue of the fact that it extends either Component or Container. Since lightweights are components, lightweights can be manipulated in exactly the same manner as their heavyweight counterparts; that is, their locations can be set, they can be painted and added to containers, and so on.
A Simple Heavyweight Component
Let's start out by implementing a simple heavyweight component that extends Panel and paints an image. Then, in order to illustrate the ease of implementing lightweight components (and to point out a potential pitfall), we'll turn our heavyweight component into a lightweight—you can see the implementation ...
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.