The how-to sections give examples of handling the events that you're most likely to care about. 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. When the user clicks the on-screen button, the button fires an action event. The single argument to the method is an ActionEvent object that gives information about the event and its source. When the user clicks a button, the button's action listeners are notified.
Event handlers can be instances of any class.
Anonymous inner classes can be somewhat confusing at first, but once you're used to them they make code clearer by keeping the implementation of an event handler close to where the event handler is registered. For information about using inner classes, see Using Adapters and Inner Classes to Handle Events . For more information about implementing event handlers, see Writing Event Listeners . This ensures that each event handler will finish executing before the next one executes. For instance, the actionPerformed method in the preceding example executes in the event-dispatching thread.