|
[Testing Beans in the BDK BeanBox] [Starting BeanBox] 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.
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.
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.
Edit the label field of the property sheet to read "stop." 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.
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. | ||||
|
| ||||||||||||