Java Reference
In-Depth Information
Both low-level and semantic events can arise simultaneously.
An event for a component can be handled by the component object itself, or by a separate
object that implements a listener interface corresponding to the event type.
A component that is to handle its own events does so by calling its enableEvents() method and
implementing the class method to process the kind of event that has been enabled.
A listener object that is registered with a component will receive notification of the events
originating with the component that correspond to the type(s) of events the listener can handle.
A listener interface for low-level events requires several event-handling methods to be
implemented.
A listener interface for semantic events declares a single event handling method.
An adapter class defines a set of empty methods for one or more low-level event interfaces. You
can create your own class defining a low-level event listener by deriving your class from an adapter
class, and then implementing the event handling methods in which you are interested.
Events in applications and in applets are handled in exactly the same way.
An Action object is an object of a class that implements the Action interface. Action
objects can be used to create menu items and associated toolbar buttons.
An Action object is automatically the listener for the menu item and toolbar button that are
created from it.
Exercises
1. Modify Sketcher to add an Exit action for the File menu and the toolbar.
2.
Modify the lottery applet to present the six numbers selected in ascending sequence.
3.
Replace the action listener for the selection buttons in the Lottery applet with a mouse
listener, and use the mousePressed() method to update the selection with a new value.
4.
Modify the Lottery applet to implement the mouse listener for a selection button as an inner
class to the Lottery class.
5.
Modify the Lottery applet to implement the control buttons on a toolbar based on Action objects.
6.
Change the Lottery applet to handle the MOUSE _ ENTERED and MOUSE _ EXITED events within
the toolbar buttons you added in the previous exercise.
7.
Add tooltips to the lucky number buttons and the toolbar buttons in the Lottery applet. (You
can make the tooltip the same for each of the lucky number buttons.)
Search WWH ::




Custom Search