GUI Changes: The AWT Grows Up |
This section tells you how to write a listener for each kind of event the AWT defines in 1.1. First, it gives an overview of the AWT listeners. After that, each listener type is discussed in its own subsection.In the table that follows, each row describes a particular group of events corresponding to one listener interface. The first column gives the name of the listener interface, with a link to the tutorial page that discusses that listener. The second column names the corresponding adapter class, if any. (For a discussion of using adapters, see the previous section.) The third column lists the methods that the listener interface contains.
To see which AWT 1.1 components can generate which kinds of events, see Events Generated by AWT Components.
Listener Interface Adapter Class Methods ActionListener
none actionPerformed(ActionEvent)
AdjustmentListener
none adjustmentValueChanged(AdjustmentEvent)
ComponentListener
ComponentAdapter
componentHidden(ComponentEvent)
componentMoved(ComponentEvent)
componentResized(ComponentEvent)
componentShown(ComponentEvent)ContainerListener
ContainerAdapter
componentAdded(ContainerEvent)
componentRemoved(ContainerEvent)
FocusListener
FocusAdapter
focusGained(FocusEvent)
focusLost(FocusEvent)
ItemListener
none itemStateChanged(ItemEvent)
KeyListener
KeyAdapter
keyPressed(KeyEvent)
keyReleased(KeyEvent)
keyTyped(KeyEvent)
MouseListener
MouseAdapter
mouseClicked(MouseEvent)
mouseEntered(MouseEvent)
mouseExited(MouseEvent)
mousePressed(MouseEvent)
mouseReleased(MouseEvent)
MouseMotionListener
MouseMotionAdapter
mouseDragged(MouseEvent)
mouseMoved(MouseEvent)
TextListener
none textValueChanged(TextEvent)
WindowListener
WindowAdapter
windowActivated(WindowEvent)
windowClosed(WindowEvent)
windowClosing(WindowEvent)
windowDeactivated(WindowEvent)
windowDeiconified(WindowEvent)
windowIconified(WindowEvent)
windowOpened(WindowEvent)
The AWT events described in the preceding table can be divided into two groups: low-level events and semantic events. Low-level events represent window-system occurrences or low-level input. Clearly, mouse and key events -- both of which result directly from user input -- are low-level events.
Component, container, focus, and window events are also low-level events. Component events let you track changes to a component's position, size, and visibility. Container events let you know when any component is added to or removed from a particular container. Focus events tell you when a component gains or loses the keyboard focus -- the ability to receive characters typed at the keyboard. Window events keep you informed of the basic status of any kind of
Window
, such as aDialog
or aFrame
.Mouse events are broken into two groups -- mouse motion events and all other mouse events -- so that an object can listen for mouse events such as clicks without requiring the system overhead necessary for generating and forwarding mouse motion events, which tend to occur frequently.
Semantic events include action, adjustment, item, and text events. These events are the result of component-specific user interaction. For example, a button generates an action event when the user clicks it, and a list generates an action event when the user doubleclicks an item in it. Adjustment events occur when a user somehow changes the value of a scrollbar. When a user selects an item in a group of items (such as a list), an item event is generated. Text events occur whenever the text in a text area or text field changes.
The next few pages have details on each type of event.
GUI Changes: The AWT Grows Up |