EventListeners

To respond to an event a component receives you register an event listener for the event type with the component. Event listeners are objects which implement a java.util.EventListener interface. The AWT defines eleven sub-interfaces of java.util.EventListener, one for each type of event:

Each of these interfaces defines the events an event listener of that type must be prepared to respond to. For example, MouseListener declares these 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)
When a component receives a mouse event, its processMouseEvent() method checks the ID of the mouse event to determine whether this is a mouse pressed, mouse released, mouse entered, or mouse exited event. Then it calls the corresponding method in each registered MouseListener object.


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