Site hosted by Angelfire.com: Build your free website today!
 

Event Handler

Every event handler requires three bits of code:

  • In the declaration for the event handler class, code that specifies that the class either implements a listener interface or extends a class that implements a listener interface. For example:

    public class MyClass implements ActionListener {
       ...
    }
  • Code that registers an instance of the event handler class as a listener upon one or more components. For example:

    someComponent.addActionListener(instanceOfMyClass);
  • Code that implements the methods in the listener interface. For example:

    public void actionPerformed(ActionEvent e) {
        ...//code that reacts to the action...
    }