Previous | Next | Trail Map | JavaBeans Tutorial | Testing Beans in the BDK BeanBox


Using Example Beans

The easiest way to understand how BeanBox works is to use it. You can construct simple beans applications without writing any Java code using BeanBox. As a first example, you can build a simple "Juggling Duke" application in which Duke will start or stop juggling depending on which of two buttons you push.

The first thing to do is add the Juggler Bean. Starting with an empty BeanBox select the Juggler Bean from the list of Beans in the Toolbox window.

Now, placing the cursor anywhere in the BeanBox will cause a Juggler Bean to be inserted in the design form. The highlighted box surrounding the Juggler indicates the Juggler is the currently selected bean.

Next, you'll need to add a start button and a stop button to control the juggler. Each of these Beans is an instance of the OurButton Bean class.

Place an instance of the button in the form.

To change the label on the button, edit the label field in the property sheet to read "start."

The text for the button changes at the same time you type it into the property sheet editor.

The next step is to specify an event to be fired by the button. A corresponding event-handler method is then selected for the Juggler Bean.

Use the edit menu to select an action event to be fired by the start button. Note that in order for this to work, the start button must be selected.

Once the actionPerformed menu selection is made, BeanBox enters a state where a line emanates from the start button and follows the mouse as you move it around the window. This indicates that the button is the selected source for the action event, and that your next mouse press should be over the target which defines appropriate event-handler methods, in this case the Juggler.

When you drag the line from the start button and release it over the Juggler Bean, a dialog appears listing applicable event handlers defined by the Juggler Bean.

Select the start method as the target for the event, then press OK. You can now press the start button; Duke should start tossing beans around in a circle over his head like a professional juggler.

You can control Duke's juggling speed by manually setting the propery value labeled animationRate in the Juggler's property sheet editor. For the appropriate property sheet editor to appear, the Juggler must be the currently selected Bean within the BeanBox frame.

To complete the example program, you need to add a stop button. Again, from the list of available beans in the Toolbox menu select OurButton.

Drag the button just below the start button, and drop it in place. Make sure the new button is the currently selected Bean. If it is, the appropriate property editor appears to the right.

Edit the label field of the property sheet to read "start." The button's label reflects your changes as you type.

Hook up the action event from the stop button to the Juggler's stop event-handler method. Make sure the stop button is the currently selected bean. Select the actionPerformed event from the Edit/Events menu.

Now drag the event line from the button source to the Juggler Bean target. Press and release the mouse button with the connection line over the Juggler. You'll now see the dialog of applicable event-handler methods defined for the Juggler Bean.

Select the stop event.

Now you're finished. You should be able to start and stop the juggler by pressing the appropriate button.

SUMMARY

A good exercise, at this point, would be to make it possible to control the Juggler's speed with a Scrollbar bean instead of by editing the numberic field in the Property editor. This project points to an important distinction not made in BeanBox but made by other builder tools.

In most builder tools the distinction between design time and run time is a little more clear. When a bean application is running, you wouldn't normally have access to the property sheet to edit properties. In the case of the Juggler, that means there would be no way to change the juggling speed while the application is running, until a scrollbar is added, and the proper events and handlers hooked up. With the current implementation, you would have to stop the application, edit the animationRate property to change the speed, then relaunch the application. Needless to say, this is not a good interactive design for most applications.

In the case of BeanBox, however, the main purpose is to test Beans and verify that introspection and event hookup works properly. The idea of running an application doesn't really make sense for BeanBox. Think of BeanBox as a reference builder tool. If your bean runs properly in BeanBox, and reports the proper events that you want your bean to fire as well as the proper event handlers for events you want it to respond to, you can be confident that your bean will work properly in other Beans-enabled builder tools.


Previous | Next | Trail Map | JavaBeans Tutorial | Testing Beans in the BDK BeanBox