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 five methods,

 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)

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 | Cafe au Lait

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