EventListener
interfaces. These are:
Each adapter class implements
the corresponding interface with a series of do-nothing methods. For example,
MouseListener declares these five methods:
public abstract void mouseClicked(MouseEvent e)
public abstract void mousePressed(MouseEvent e)
public abstract void mouseReleased(MouseEvent e)
public abstract void mouseEntered(MouseEvent e)
public abstract void mouseExited(MouseEvent e)
Therefore, MouseAdapter
looks like this:
package java.awt.event;
import java.awt.*;
import java.awt.event.*;
public class MouseAdapter implements MouseListener {
public void mouseClicked(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
}
By subclassing MouseAdapter
rather than implementing MouseListener
directly,
you can avoid having to write the methods you don't actually need. You only override those that you plan to actually implement.