Basic HTML version of Foils prepared 13 October 97

Foil 44 Adapter Classes

From Java Tutorial, July 1, 1996 CSC499(JSU) CPS406/606 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox

Adapter classes for Foil 44
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) { . . . }
  • }



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998