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

Get JavaBeans Unleashed 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.