Java Reference
In-Depth Information
For example, a class that implements the
MouseMotionListener
interface from
java.awt.event
must implement the methods:
public void mouseDragged(MouseEvent e)
public void mouseMoved(MouseEvent e)
The presence of these methods does not imply that the methods will take an action when a
client calls them. In fact, it would not be uncommon to react to the
mouseDragged()
method but to ignore to calls to the
mouseMoved()
method.
SOLUTION 2.4
A class that implements
WindowListener
must implement all the methods the interface
declares, even if the class will ignore these methods when called. The
WindowAdapter
class
ignores
all
the methods in Window-Listener. This lets a subclass implement only the methods
that it wants to react to, as Figure B.1 shows. The anonymous class in Figure B.1 can react to
only the
windowClosing()
event, without having to implement dummy methods for the
other methods specified in the
WindowListener
interface.