Basic HTML version of Foils prepared Sept 21 1998

Foil 44 Adapter Classes

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

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 Sat Nov 28 1998