JavaBean Events   «Prev 

Wiring JavaBeans together with Events

Objective: Wire three Beans together using events.
In this exercise you wire three Beans together using events.
  1. Launch the BeanBox
  2. Insert one (1) Juggler Bean
  3. Insert two (2) OurButton Beans
  4. Change the label property of one OurButton Bean to "Start"
  5. Change the label property of the other OurButton Bean to "Stop"
The BeanBox window should now look something like this:
beanbox
Characteristics of the bean box

BeanBox window

You are now going to wire the first OurButton Bean to the Juggler Bean so that pressing the button starts the animation.
  1. Select the OurButton Bean labeled "Start".
  2. In the BeanBox window, click on the Edit menu item
  3. In the drop-down menu, select Events >> action >> actionperformed

You will see a red line originating from the OurButton Bean. This line is used to graphically connect a listener Bean that will receive actionPerformed events.
  1. Click on the Juggler Bean to make it the event listener.
  2. In the EventTargetDialog window, select the startJuggling() public method.
The Start button is now successfully wired to the Juggler Bean and can be used to start the animation. To stop the animation:
  1. Select the OurButton Bean labeled "Stop".
  2. In the BeanBox window, click on the Edit menu item
  3. In the drop-down menu, select Events >> action >> actionperformed
  4. Click on the Juggler Bean to make it the event listener.
  5. In the EventTargetDialog window, select the stopJuggling() public method.
To test the connected Beans, first disable design time mode, then enable runtime mode.
Click the Submti button to return to the lesson page.