例如,与键盘事件KeyEvent相对应的接口是:
  public interface KeyListener extends EventListener {
     public void keyPressed(KeyEvent ev);
     public void keyReleased(KeyEvent ev);
     public void keyTyped(KeyEvent ev);
  }

  注意到在本接口中有三个方法,那么java运行时系统何时调用哪个方法?其实根据这三个方法的方法名就能够知道应该是什么时候调用哪个方法执行了。当键盘刚按下去时,将调用keyPressed( )方法执行,当键盘抬起来时,将调用keyReleased( )方法执行,当键盘敲击一次时,将调用keyTyped( )方法执行。

  又例如窗口事件接口:
  public interface WindowListener extends EventListener{
     public void windowClosing(WindowEvent e);
     //把退出窗口的语句写在本方法中
     public void windowOpened(WindowEvent e);
     //窗口打开时调用
     public void windowIconified(WindowEvent e);
     //窗口图标化时调用
     public void windowDeiconified(WindowEvent e);
     //窗口非图标化时调用
     public void windowClosed(WindowEvent e);
     //窗口关闭时调用
     public void windowActivated(WindowEvent e);
     //窗口激活时调用
     public void windowDeactivated(WindowEvent e);
     //窗口非激活时调用
  }

  AWT的组件类中提供注册和注销监听器的方法:

  ◇ 注册监听器:
  public void add<ListenerType> (<ListenerType>listener);

  ◇ 注销监听器:
  public void remove<ListenerType> (<ListenerType>listener);

  例如Button类:(查API)
  public class Button extends Component {
     ……
     public synchronized void addActionListener(ActionListener l);
     public synchronized void removeActionListener(ActionListener l);
     ……}