Java Reference
In-Depth Information
The methods that add or remove listeners are provided by the source that generates
events. For example, the Component class provides methods to add and remove keyboard
and mouse event listeners.
Event Listeners
A listener is an object that is notified when an event occurs. It has two major requirements.
First, it must have been registered with one or more sources to receive notifications about
specific types of events. Second, it must implement methods to receive and process these
notifications.
The methods that receive and process AWT events are defined in a set of interfaces,
such as those found in java.awt.event . For example, the MouseMotionListener interface
defines methods that receive notifications when the mouse is dragged or moved. Any object
may receive and process one or both of these events if it provides an implementation of this
interface.
Event Classes
The classes that represent events are at the core of Java's event handling mechanism. At
the root of the Java event class hierarchy is EventObject , which is in java.util . It is the
superclass for all events. The class AWTEvent , defined within the java.awt package, is
a subclass of EventObject . It is the superclass (either directly or indirectly) for all AWT-
based events used by the delegation event model.
The package java.awt.event defines several types of events that are generated by vari-
ous user interface elements. Table 15-2 enumerates several commonly used ones and
provides a brief description of when they are generated.
Search WWH ::




Custom Search