An "event listener" is an object to which a component has delegated the task of handling a particular type of event. When the component experiences input, an event of the appropriate type is constructed and then sent as the parameter of a standard method called on the listener.
In the preceeding section, an ActionListener for the Button component was demonstrated. The required steps included:
Fortunately, the java.awt.event package provides seven "adapter" classes, one for each listener interface that defines more than one abstract method. An "adapter" is simply a class that implements an interface by providing do-nothing methods. In our example, we defined a class that extends WindowAdapter, and then we only had to override the one method we were interested in - windowClosing().
[Source: Roberts, p313-318]
Interface/Adapter |
methods |
add method |
ActionListener | actionPerformed(ActionEvent) | addActionListener() |
AdjustmentListener |
adjustmentValueChanged (AdjustmentEvent) | addAdjustmentListener() |
ComponentListener ComponentAdapter |
componentHidden(ComponentEvent) componentMoved(ComponentEvent) componentResized(ComponentEvent) componentShown(ComponentEvent) | addComponentListener() |
ContainerListener ContainerAdapter |
componentAdded(ContainerEvent) componentRemoved(ContainerEvent) | addContainerListener() |
FocusListener FocusAdapter |
focusGained(FocusEvent) focusLost(FocusEvent) | addFocusListener() |
ItemListener | itemStateChanged(ItemEvent) | addItemListener() |
KeyListener KeyAdapter |
keyPressed(KeyEvent) keyReleased(KeyEvent) keyTyped(KeyEvent) | addKeyListener() |
MouseListener MouseAdapter |
mouseClicked(MouseEvent) mouseEntered(MouseEvent) mouseExited(MouseEvent) mousePressed(MouseEvent) mouseReleased(MouseEvent) | addMouseListener() |
MouseMotionListener MouseMotionAdapter |
mouseDragged(MouseEvent) mouseMoved(MouseEvent) | addMouseMotionListener() |
TextListener | textValueChanged(TextEvent) | addTextListener() |
WindowListener WindowAdapter |
windowActivated(WindowEvent) windowClosed(WindowEvent) windowClosing(WindowEvent) windowDeactivated(WindowEvent) windowDeiconified(WindowEvent) windowIconified(WindowEvent) windowOpened(WindowEvent) |