O'Reilly logo

JavaBeans Unleashed by Rick Leinecker, Dr. Donald Doherty

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

Extending the java.awt.Panel Class

You create containers all the time when you write Java beans. Any bean that can hold another bean is a container. For instance, all beans extended from an Abstract Windowing Toolkit (AWT) control are containers. In this section, you write a simple Dot bean and a container bean, which is extended from the java.awt.Panel class, named MyContainer1. You add Dot beans to the container bean.

The Dot bean is extended from the java.awt.Canvas class and displays a small red circle. The code is shown in Listing 8.1. The reason for creating the Dot bean is to have something for a container bean to hold.

Listing 8.1 Source code for Dot.java
 package sams.containers; import java.awt.Canvas; import java.awt.Color; ...

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