Building a bevy of beans: Create reusable JavaBeans components
With the basics of beans in the bag, you're now ready to see how easy it is to develop more advanced beans
By Merlin Hughes, JavaWorld.com, 09/01/97
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
In this short series, we are examining the development of JavaBeans software components. Ultimately, most beans will be manipulated
in a beans development environment; however, we are only concerned here with the source-level aspects of the framework. The
advantages of developing JavaBeans -- that is, developing to the JavaBeans specification -- are severalfold, among them:
- Beans can be easily manipulated in visual development environments by users who need not be technically skilled in source-level
Java development.
- Because of the standard interface, beans are readily distributable, which allows third-party components to be more easily
integrated into development efforts.
- Developers can easily transfer code that has been developed for one project into a reusable library of components, which can
be accessed in future development efforts.
The eye of the storm
In the
first part of this series, we developed two simple beans: a non-visual alarm bean and a graphical left-arrow/right-arrow bean. Both were augmented
with visual
customizer and
bean information classes. In the beans we cover this month, we won't be providing customizers; instead, we'll concentrate on using existing
beans and components to create bigger, better beans.
Prerequisites
As the continuation of a two-part series, I will assume familiarity with the issues discussed in the previous installment,
including the supplementary articles and resources.
The beans
From start to finish of this series, we develop the following beans:
| AlarmBean
|
|
A non-graphical bean that fires off an event after a specified delay. |
| ArrowBean
|
|
A graphical left-arrow/right-arrow bean.
|
ProgressBean
|

|
A graphical progress-display bean.
|
NumberFieldBean
|

|
A graphical numeric TextField bean with roll buttons. This bean makes use of the ArrowBean bean.
|
FontChooserBean
|

|
A graphical font-chooser bean. This bean makes use of the NumberFieldBean bean.
|
FontSelectorBean
|

|
A graphical font-chooser bean that displays the current font and provides OK/Cancel buttons. This bean makes use of the FontChooserBean
bean.
|
FontDialogBean
|

|
A graphical font-chooser bean that pops up the font selector in a separate dialog. This bean makes use of the FontSelectorBean
bean.
|
We discussed the AlarmBean and ArrowBean beans in detail last month; in this episode, we will discuss the remaining beans in varying levels of detail.
You may be wondering why we're building three font beans. The ultimate goal is simply to produce a font selector bean that
pops up a font dialog when the user clicks on a button. This task very naturally divides into the three beans we'll produce:
The first is the user interface for the font selection, the second adds dialog controls and a font sample, and the third introduces
a button to pop up the dialog and contains the basic dialog-handling code.
Without beans, we would have to develop these items as specialized AWT components or as a single monolithic class; using beans,
we can develop the three parts as independent beans that are reusable in their own right.
- Digg
- Reddit
- SlashDot
- Stumble
- del.icio.us
- Technorati
- dzone
Resources
- Download this article and the complete source code as a gzipped tar file
http://www.javaworld.com/javaworld/jw-09-1997/step/jw-09-step.tar.gz
- Download this article and the complete source code as a zip file
http://www.javaworld.com/javaworld/jw-09-1997/step/jw-09-step.zip
- Be sure to read "Double Shot, Half Decaf, Skinny LatteCustomize your Java," the latest installment of the JavaWorld's new JavaBeans column
http://www.javaworld.com/javaworld/jw-09-1997/jw-09-beans.html
- JavaBeans author Mark Johnson doubled his efforts this month and wrote a companion piece to his new column describing Sun's
bean testing tool, the BeanBox
http://www.javaworld.com/javaworld/jw-09-1997/jw-09-beanbox.html
- The new Java Foundation Classes (JFC) http://www.javasoft.com/products/jfc
- Download the latest BDK from JavaSoft's JavaBeans Web site http://splash.javasoft.com/beans/
- The JavaBeans specification http://splash.javasoft.com/beans/spec.html
- The "Glasgow" JavaBeans specification http://splash.javasoft.com/beans/glasgow.html
- Late-breaking advice for the JavaBeans developer from the JavaBeans Advisor http://splash.javasoft.com/beans/Advisor.html
- Online training from the Java Developer Connection http://developer.javasoft.com/developer/onlineTraining/
- Read Intermediate & Advanced Java Programming Material by Richard G. Baldwin http://www.phrantic.com/scoop/Java000.htm
- Previous Step by Step articles