Creating a Bean Event Set
See Also
- In the Filesystems window, find the class for your bean, expand its node,
and right-click Bean Patterns.
- In the contextual menu, choose Add
Unicast
Event Source or Add
Multicast
Event Source. Use the Unicast option to add an event set that is deliverable to only
one listener. Use Multicast for an event set that is deliverable to more than one
listener.
The New Unicast/Multicast Event Set dialog box appears, enabling you to
customize the code to be generated for the event set.
- In the Type field, either type in a fully qualified listener interface
name for the event class type or use the combo box to select one. The listener
interface must extend java.util.EventListener.
- Select one of these options for implementing the event set:
- Generate Empty. Generates an empty implementation.
- Generate Implementation. Generates a simple implementation for
one listener in a Unicast event set.
- Generate ArrayList Implementation. Generates a simple implementation
for multiple listeners in a Multicast event set.
- Generate EventListenerList. Generates an implementation using
the EventListenerList support class from the javax.swing.event
package. This option only appears for Multicast event sets.
If you selected Generate Empty, skip to Step 7.
- If you specified a nonempty implementation in Step 4, the Generate Event
Firing Methods checkbox is enabled. Select this checkbox to generate event
firing methods for all listeners. A method is generated for every method in
the listener interface.
- If you selected Generate Event Firing Methods, the Pass Event as Parameter
checkbox is enabled. Select this checkbox to add the event as a parameter
to each event firing method. The event is passed to the listeners in the body
of the firing method.
If you do not select the Pass Event as Parameter checkbox, each firing
method has the same parameters as the constructor of the event object class.
The constructor is called in the body of the firing method, and then the
newly created event is passed to the listeners. If there are multiple constructors
for the event class, the code generator behaves as if the Pass Event as
Parameter option is enabled.
- Click OK to generate an addEventNameListener method
and a RemoveEventNameListener method to your source
code, along with firing methods if you specified them.
For more information about unicast and multicast event delivery and related
APIs, see the JavaBeans specification at
http://java.sun.com/beans/docs/spec.html
Legal Notices