from Component, such as Applet, can generate events. For example, you can receive key and
mouse events from an applet. (You may also build your own components that generate
events.) In this chapter, we will be handling only mouse and keyboard events, but the
following two chapters will be handling events from the sources shown in Table 22-2.
Event Listener Interfaces
As explained, the delegation event model has two parts: sources and listeners. Listeners are
created by implementing one or more of the interfaces defined by the java.awt.event package.
When an event occurs, the event source invokes the appropriate method defined by the
listener and provides an event object as its argument. Table 22-3 lists commonly used listener
interfaces and provides a brief description of the methods that they define. The following
sections examine the specific methods that are contained in each interface.
The ActionListener Interface
This interface defines the actionPerformed( ) method that is invoked when an action event
occurs. Its general form is shown here:
void actionPerformed(ActionEvent ae)
Defines one method to receive action events.
Defines one method to receive adjustment events.
Defines four methods to recognize when a component is hidden,
moved, resized, or shown.
Defines two methods to recognize when a component is added to
or removed from a container.
Defines two methods to recognize when a component gains or loses
Defines one method to recognize when the state of an item changes.
Defines three methods to recognize when a key is pressed, released,
Defines five methods to recognize when the mouse is clicked, enters
a component, exits a component, is pressed, or is released.
Defines two methods to recognize when the mouse is dragged or
Defines one method to recognize when the mouse wheel is moved.
Defines one method to recognize when a text value changes.
Defines two methods to recognize when a window gains or loses
Defines seven methods to recognize when a window is activated,
closed, deactivated, deiconified, iconified, opened, or quit.
Commonly Used Event Listener Inter faces
Search WWH :