Archives
 
 
 
  Special
 
 
 
  About Us
 
 
 

Newsletter
Free E-mail Newsletter from BYTE.com

 
    
           
Visit the home page Browse the four-year online archive Download platform-neutral CPU/FPU benchmarks Find information for advertisers, authors, vendors, subscribers Request free information on products written about or advertised in BYTE Submit a press release, or scan recent announcements Talk with BYTE's staff and readers about products and technologies

ArticlesLife in the BeanBox


June 1997 / Javatalk / Beyond GUI Graphics / Life in the BeanBox

If you want to check out Java component technology, you can download JavaSoft's Beans Development Kit (BDK) from http://www.javasoft.com . The BDK, which is available for Solaris and Windows 95 and NT, requires that you have JDK 1.1 (available from the same Web site and now in general release) downloaded and installed.

Although the BDK's primary utility is as a collection of API documents and sample source cod e, it's more than that. Specifically, the BDK also includes an executable environment for testing JavaBeans. This environment, which you can think of as a software test lab, is a frame-based Java application called the BeanBox ( see the screen ).

During operation, the BeanBox provides three windows. The leftmost is the bean palette, a holding area for candidate beans under test. In the middle, the BeanBox composition window provides a staging area where live beans perform. When you click on a bean in the palette and then click on a location in the composition window, the bean is instantiated and ready to test. The right window is a properties inspector window. When you select a bean in the BeanBox, this window is filled with any editable properties the bean possesses.

The BeanBox contains 16 beans. These range from simple (for example, the JellyBean, which draws a rounded rectangle and supports two properties) to more complex ones, such as the JDBC SELECT bean, which launches a SQL SELECT statement at a Java Database Connectivity database server. The composition window is itself a container bean.

Bean Events and Bound Properties

Beans do not exist independently of each other. Multiple beans within a container must have a mechanism for communicating with one another. An important aspect of a JavaBean is its ability to trigger and/or respond to events.

To properly test the event-managing capabilities of a bean, whether as an event source or a target, you need to wire beans together. The BeanBox lets you do this. Once a bean is in the composition window, you can select it and, through the window's edit menu, browse the event-listener interfaces that the bean implements. You can connect this event-listener interface to any other bean (which becomes the receiver of the event) that implements that interface.

It works like this: Select a bean in the composition window. This will become the event-source bean. From the menu, select the event-listener interface that you want to hook to a receiving bean. You also select the EventObject argument associated with this interface (the purpose of this argument will become clear in a moment). The BeanBox draws a rubber-band line that tracks the mouse. You then select the receiving bean (anchoring the rubber band), which causes the BeanBox to open a dialog box showing the methods in the target bean that can accept the event from the source bean. Which methods are compatible on the target depend on the EventObject you selected back on the source bean.

Pick the target method, and the BeanBox automatically creates, compiles, and loads what is referred to as an "event-adapter class." This is the actual plumbing that connects the source bean's event to the target's receiving method. Once this class is built, you can test the source and target's behavior, verifying that the source event is properly handled by the receiving bean.

The BeanBox also lets you test what are known as "bound properties." A bound property triggers a PropertyChange event whenever that property is modified. Consequently, you can wire the property's event to a target bean using much the same mechanism as described above. For example, a text-display bean could properly track the color of a rectangle-drawing bean. Whenever the rectangle's color property gets modified, the text-display bean is notified.

Included with the BDK is a tutorial that guides you through the process of connecting button beans to the animated Juggling Duke bean (as shown in the screen ). This is worthwhile for getting a quick feel for how beans perform event-handling under JDK 1.1. More useful are the later examples in the tutorial that use an analogy of water flowing from sources to destinations through pipes and valves to illustrate the dynamics of event management.


Juggle the JavaBeans

screen_link (23 Kbytes)

The BDK's BeanBox is a complete proving ground for JavaBeans.


Up to the Javatalk section contentsGo to previous article: Life in the BeanBoxSearchSend a comment on this articleSubscribe to BYTE or BYTE on CD-ROM  
Flexible C++
Matthew Wilson
My approach to software engineering is far more pragmatic than it is theoretical--and no language better exemplifies this than C++.

more...

BYTE Digest

BYTE Digest editors every month analyze and evaluate the best articles from Information Week, EE Times, Dr. Dobb's Journal, Network Computing, Sys Admin, and dozens of other CMP publications—bringing you critical news and information about wireless communication, computer security, software development, embedded systems, and more!

Find out more

BYTE.com Store

BYTE CD-ROM
NOW, on one CD-ROM, you can instantly access more than 8 years of BYTE.
 
The Best of BYTE Volume 1: Programming Languages
The Best of BYTE
Volume 1: Programming Languages
In this issue of Best of BYTE, we bring together some of the leading programming language designers and implementors...

Copyright © 2005 CMP Media LLC, Privacy Policy, Your California Privacy rights, Terms of Service
Site comments: webmaster@byte.com
SDMG Web Sites: BYTE.com, C/C++ Users Journal, Dr. Dobb's Journal, MSDN Magazine, New Architect, SD Expo, SD Magazine, Sys Admin, The Perl Journal, UnixReview.com, Windows Developer Network