Growing Java Beans
Volume Number: 14
Issue Number: 9
Column Tag: JavaTech
by Andrew Downs
Edited by the MacTech Editorial Staff
A code-based intro to Java's component architecture
JavaBeans is the Java component architecture. This article discusses and demonstrates
how to write several simple components (hereafter referred to as Beans). The reader
should have a general familiarity with Java. The code in this article was developed
using the Apple Mac OS Runtime for Java (MRJ) version 2.0 and the MRJ SDK 2.0.1
ea2.
For additional background information, several related articles previously published
in MacTech are listed in the reference section at the end of this article. Several books
are also listed.
A Java Bean bears a strong resemblance to a well-written Java application. But since
it is a component, a Bean's scope is usually smaller than that of an entire application,
making it easier to develop.
Here is a partial list of Bean characteristics. Beans should:
• expose accessor methods (e.g. getValue() and setValue()) to allow
retrieval and changing of attribute values by external sources;
• allow for easy mixing and matching via GUI development tools;
• generate or respond to appropriate events;
• save their state using the Java Serialization mechanism.
In this article, we will explore the code behind two relatively simple Beans. They
contain enough of the above-listed features to make them interesting, while remaining
easy to read and understand. One of the Beans displays a sequence of lights similar to a
U.S.-style traffic light. The other Bean changes the sequence of the light display. We
will look at the code for these classes later.
Figure 1 shows the two Beans running within a Java Frame object. (A Frame is a
platform-specific window.) Figure 2 shows the Beans running inside the BeanBox, a
GUI tool from JavaSoftthat allows you to instantiate, connect, and test Bean behavior.
The BeanBox is provided free of charge from JavaSoft, as part of the Beans
Development Kit (BDK). Since it is written in Java, the BeanBox can be installed on