
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
428
|
Chapter 19: The Delegation Event Model
EventObject
A foundation class that provides basic services for all event objects
EventListener
A marker interface that all event listener interfaces must extend
Let’s see how those items look in real code.
The EventListenerList Class
The EventListenerList class stores EventListener objects in an array and defines three
methods to manage those objects:
addObj( )
Places a new object in the array (if it isn’t already in the array)
removeObj( )
Removes an object from the array
getListeners( )
Returns a copy of the array (used by the event source during event broadcast)
Recall our earlier Chat example, in which the event source was the Chat class. In that
example, an instance of the Chat class would create an EventListenerList instance to
contain listener objects that implement the ChatListener interface. At event time, the
Chat instance would invoke the appropriate event method on all objects in the
EventListenerList.
Figure 19-1. Logic flow in the delegation event model
5a
EventListenerList
getListeners()
addObj()
removeObj()
EventListener
EventSourceClass
listeners:EventListenerList
addEventTypeListener(l)
removeEventTypeListener(l)
fireOnEventName()
implements
implements
EventObject
extends
EventTypeEvent
getEventInfo()
EventListenerClass
onEventName(EventTypeEvent) ...