Event Hookups and Adapters
Beans use events to communicate. As we mentioned in Chapter 16, events are not limited to GUI components
but can be used for signaling and passing information in more general
applications. An event is simply a notification; information describing
the event and other data are wrapped up in a subclass of EventObject and passed to the receiving object
by a method invocation. Event sources register listeners that want to
receive the events when they occur. Event receivers implement the
appropriate listener interface containing the method needed to receive the
events. This is Java’s general event mechanism in a nutshell.
It’s often useful to place an adapter between an event source and a listener. An adapter can be used when an object doesn’t know how to receive a particular event; it enables the object to handle the event anyway. The adapter can translate the event into some other action, such as a call to a different method or an update of some data. One of the jobs of NetBeans is to help us hook up event sources to event listeners. Another job is to produce adapter code that allows us to hook up events in more complex ways.
Taming the Juggler
Let’s get our juggler under control with the following steps:
Using the Properties pane, change the label of your button to read “Start.”
Now click the small Connection Mode icon at the top of the GUI builder (the second icon, showing two items with arrows pointing at one another).
After pressing the button, NetBeans is ...