Java Reference
In-Depth Information
Because you are developing the bean, you get to decide how to keep track
of listeners of an event. In addition, you get to decide how many listeners
a bean can have for a particular event. For example, you might have a
situation in which only one listener makes sense for an event. In this
situation, you would not need a data structure, but would need only a
field to keep track of the listener.
The java.util package contains a class named TooManyListenersException
that can be thrown by the add<event_name>Listener method when the
bean does not want any more listeners registering for the event.
Now that the Radio bean is a source of a VolumeEvent, it can be hooked up
to other beans that listen for this event. To deploy this bean, it needs to appear
in a JAR file along with the VolumeEvent and VolumeListener classes. The
manifest file should look like the following:
Manifest-Version: 1.0
Name: Radio.class
Java-Bean: True
Name: VolumeEvent.class
Java-Bean: False
Name: VolumeListener.class
Java-Bean: False
After the bean is deployed, the Bean Builder tool will recognize the Radio as
a source of a VolumeEvent and let other beans register for it. Figure 19.25
shows the first step of the Interaction Wizard that appears when the Radio
bean is hooked up to another bean. Notice that the methods of the VolumeLis-
tener interface appear in the list of available event sources.
Figure 19.25
Methods of the VolumeListener interface appear as events for the Radio
bean.
Search WWH ::




Custom Search