For every Event Listener interface with more than one method, there is a corresponding Event Adapter class. For example, there is an MouseAdapter class to go with the MouseListener interface.
|
The adapter class implements its corresponding listener class by providing all of the required methods, but which have bodies that do nothing.
|
For interfaces like MouseListener and MouseMotionListener, this can be handy because there are several methods in each interface. Typically, you don't want to implement all of the methods. So it is more convenient to make a class which extends the adapter class than to directly implement the listener class.
-
class MouseHandler extends MouseAdapter
-
{ ... // override only the methods that you want to implement
-
public void mousePressed(MouseEvent e) { . . . }
-
}
|