13.3. Lightweight Components in Java 1.1

Java 1.1 introduced “lightweight” components that inherit directly from Component and have no associated native window-system “peer.” Any region not directly drawn in the paint method will let the underlying component show through. For instance, Listing 13.4 shows a BetterCircle class that uses this approach. The code is similar to the version that used Canvas (Listing 13.1), with the exception that here we have to override getPreferredSize and getMinimumSize to do what Canvas already does: simply report its current size. In general, these two methods should be used to calculate the optimum and minimum sizes for the component. Listing 13.5 shows BetterCircle used in the same way as Circle was used in ...

Get Core Web Programming, Second 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.