We're going to learn to "beanify" an applet by example. The applet we're going to beanify, ColorFadeBar, produces a title bar (perhaps for a Web page), with a color gradient, like this:
![]()
Figure 1: ColorFadeBar applet in action
You can see the full source code for this applet here. You may want to open another browser window (or print the applet) so you can follow along with this discussion.
The first task in beanifying an existing class (whether that class is an applet or not) is to identify what attributes of
the class can be considered properties. (See my previous article on customization in the Resources below.) Properties allow the user of a class to customize how the class appears or behaves. For example, Figure 2 shows some
attributes of the ColorFadeBar applet that are programmable (via the <PARAM> tags within an <APPLET> tag in HTML).

Figure 2: Programmable attributes of a ColorFadeBar
The font, font size, color, and alignment of the text message are all parameterized, as are the beginning and ending colors
for the cool background fade effect, and the width and height of the applet. There are also two parameters (X0 and DY, not shown here; see Table 1 below) that allow you to nudge the text vertically or horizontally for various purposes.
These attributes of the applet aren't properties yet. A JavaBeans property consists of methods that allow the retrieval and/or modification of some internal state of a class. The applet currently doesn't have methods that provide that functionality.
Although applet parameters are often directly translatable to properties (since their purpose usually is to affect the appearance
or behavior of an object), they are fundamentally different mechanisms. An applet accesses a parameter by calling java.applet.Applet.getParameter(), and then converting whatever string is returned to the appropriate type. A property, on the other hand, consists of a method
or methods that the class exposes (that is, makes publicly available) in order to allow external agents to access encapsulated information.
If you used parameters while writing your applet, you were probably already thinking in terms of properties. In fact, the
parameters to your applet are your first candidates for the properties of your new bean. Our ColorFadeBar applet has the following parameters:
| Parameter | Meaning |
|---|
| WIDTH | The width of the applet |
| HEIGHT | The height of the applet |
| STARTCOLOR | The beginning color for the background fade |
| ENDCOLOR | The ending color for the background fade |
| TEXTCOLOR | The color in which to render the message |
| TEXT | The message text |
| FADEDIR | Background fade direction (left, right, up, down) |
| TEXTDIR | Text alignment (left, center, right) |
| FONT | The name of the font for TEXT |
| FONTSIZE | The size of the font for TEXT |
| X0 | Text left or right margin offset from applet edge (depending on TEXTDIR; default 5) |
| DY | Text baseline offset (default 0) |
These parameters can be used to customize how the applet works. We first need to identify what the properties of the new bean will be, and then add accessor functions for them. Table 2 shows the properties I've chosen for the new bean, a description of each property, and the parameter or parameters to which the property corresponds.