Handling GUI events in a Swing application is all about linking events to listeners. Events can be generated many ways but are often generated by the user through an input device such as a mouse or keyboard. The base event class is EventObject. Listeners “listen” for specific events on specific objects and execute whatever code the application developer has written. The base listener class is EventListener. There are several design approaches to the linking of events to listeners. These design approaches are:
External Class
External class with fields
Inner class (field level)
Inner class (local-variable level)
Existing class
Anonymous class
Anonymous class and instance
In the end, handling GUI events boils down to the same three tasks:
Choose the event and component of interest;
Implement the appropriate event listener giving it the desired application behavior;
Register the listener with the component of interest.