Skill-Building Exercises


Summary

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:

  1. External Class

  2. External class with fields

  3. Inner class (field level)

  4. Inner class (local-variable level)

  5. Existing class

  6. Anonymous class

  7. Anonymous class and instance

In the end, handling GUI events boils down to the same three tasks:

  1. Choose the event and component of interest;

  2. Implement the appropriate event listener giving it the desired application behavior;

  3. Register the listener with the component of interest.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net