
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Core Implementation
|
431
In order to receive an event notice (and with it, an EventObject instance), an event
listener object must be an instance of a class that implements the appropriate event
listener interface. The event source class determines which interface its event listen-
ers must implement. All specific event listener interfaces are subclasses of the generic
EventListener interface, described next.
The EventListener Interface
The EventListener interface is a so-called marker interface (as explained in
Chapter 8). It simply tags a class as being part of the delegation event model struc-
ture. Each implementation of the delegation event model must supply an
EventListener subinterface listing all methods that can be triggered by the event
source. Listener classes wishing to register to receive events from a particular event
source must implement that source’s corresponding EventListener subinterface. For
example, suppose the class OrderForm is an event source and the class
FormValidator is an event listener. In order to receive events from OrderForm, the
FormValidator class would have to implement, say, FormListener. The FormListener
interface would extend EventListener and define the OrderForm’s events—perhaps
onFormSubmit( ) and onFormReset( ).
Example 19-3 shows the code for ...