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 evt)
 public abstract void mousePressed(MouseEvent evt)
 public abstract void mouseReleased(MouseEvent evt)
 public abstract void mouseEntered(MouseEvent evt)
 public abstract void mouseExited(MouseEvent evt)

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 evt) {}
  public void mousePressed(MouseEvent evt) {}
  public void mouseReleased(MouseEvent evt) {}
  public void mouseEntered(MouseEvent evt) {}
  public void mouseExited(MouseEvent evt) {}


By subclassing MouseAdapter rather than implementing MouseListener directly, you avoid having to write the methods you don't actually need. You only override those that you plan to actually implement.

Previous | Next | Top | Cafe au Lait

Copyright 1997, 2006 Elliotte Rusty Harold
Last Modified April 26, 2006