Adapter Classes

The AWT provides a number of adapter classes for the different 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.


Previous | Next | Top
Last Modified August 7, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@sunsite.unc.edu