JavaBean Events   «Prev  Next»
Lesson 7 Cleaner event handling with event adapters
ObjectiveLearn how event adapters are a cleaner approach to event handling.

Cleaner Event Handling using Event Adapters

Implementing event listener interfaces to handle events is often annoying because it requires you to implement all the event response methods in an interface, regardless of which ones you need. To alleviate this problem, the Java 1.1 API supplies event adapters[1], which are "convenience classes" that make the handling of events much cleaner. Event adapters enable you to implement only the event response methods you need, freeing you from the hassle of writing empty methods you don't need just to conform to an interface.
Event adapters are classes, which is what allows you to override only the methods you need in them. There is a unique event adapter class for each low-level event listener interface. There are no event adapter classes for semantic event listener interfaces since the interfaces define only one method each. Following are the event adapter classes provided in the Java 1.1 API:
  1. ComponentAdapter
  2. FocusAdapter
  3. KeyAdapter
  4. MouseAdapter
  5. MouseMotionAdapter
  6. WindowAdapter

In the next lesson, you learn how to use event adapters.
[1]event adapter: A "convenience class" used to make the handling of events much cleaner.