Summary

Internally, the event-handling system used with Swing is much more sound, and more easily extended to handle new types of user interaction.

Externally, the new system should also make more sense from a programming standpoint. Event handling is added to a program through the same steps:

  • A listener interface is added to the class that will contain the event-handling methods.

  • A listener is added to each component that will generate the events to handle.

  • The methods are added, each with an EventObject class as the only argument to the method.

  • Methods of that EventObject class, such as getSource(), are used to learn which component generated the event and what kind of event it was.

Once you know these steps, you can work with each of the different ...

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.