O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required