18.9. Summary

In this chapter you have learned how to handle events in your applications and in your applets. Events are fundamental to all window-based applications, as well as most applets, so you'll be applying the techniques you have seen this chapter throughout the rest of the book.

The most important points I have discussed in this chapter are:

  • A user interaction generates an event in the context of a component.

  • Two categories of events are associated with a component: low-level events from the mouse or keyboard, or window system events such as opening or closing a window; and semantic events that represent component actions such as pressing a button or selecting a menu item.

  • Both low-level and semantic events can arise simultaneously.

  • An event for a component can be handled by the component object itself, or by a separate object that implements a listener interface corresponding to the event type.

  • A component that is to handle its own events does so by calling its enableEvents() method and implementing the class method to process the kind of event that has been enabled.

  • A listener object that is registered with a component will receive notification of the events originating with the component that correspond to the type(s) of events the listener can handle.

  • A listener interface for low-level events requires several event-handling methods to be implemented.

  • A listener interface for semantic events declares a single event-handling method.

  • An adapter class defines a set of empty methods ...

Get Ivor Horton's Beginning Java™ 2, JDK™ 5th 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.