Friday, August 19, 2016

Using Bound Properties

Using Bound Properties

A Bean that has a bound property generates an event when the property is changed. The event is of type PropertyChangeEvent and is sent to objects that previously registered an interest in receiving such notifications.
The TickTock Bean is supplied with the BDK. It generates a property change event every N seconds. N is a property of the Bean that can be changed via the Properties window of the BDK. The next example builds an application that uses the TickTock Bean to automatically control the Colors Bean.

Steps

start the BDK and create an instance of the Colors Bean in the BeanBox window. Create an instance of the TickTock Bean. The Properties window should show one property for this component. It is “Interval” and its initial value is 5. This represents the number of seconds that elapse between property change events generated by the TickTock Bean. Change the value to 1.


Now you need to map events generated by the TickTock Bean into method calls on the Colors Bean. Follow these steps:

1. Go to the menu bar of the BeanBox and select Edit | Events | propertyChange | propertyChange. You should now see a line extending from the button to the cursor.

2. Move the cursor so that it is inside the Colors Bean display area, and click the left mouse button. You should see the Event Target Dialog dialog box.

3. The dialog box allows you to choose a method that should be invoked when this event occurs. Select the entry labeled “change” and click the OK button.

You should see a message box appear very briefly, stating that the tool is “Generating and compiling adaptor class.”

You should now see the color of your component change every second.

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home