
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
430
|
Chapter 19: The Delegation Event Model
In addition to managing event listeners in an EventListenerList instance, the event
source must broadcast an event description to its listeners at event time. The descrip-
tion takes the form of an EventObject subclass. Let’s create the EventObject class next.
The EventObject Class
The EventObject class is the parent of all classes that describe an event. It provides a
reference to its event source, which lets event listeners retrieve data from the event
source or perform actions on it. Subclasses of EventObject define properties that
describe an event and often provide methods to access those properties.
The EventObject class defines a single method, getSource( ), which returns a refer-
ence to the event source that created the current EventObject instance.
The event source reference is supplied to the EventObject via its constructor. As we
described earlier, our chat application’s EventObject subclass would be ChatEvent,
which would define the properties:
messageText, messageSender, oldUserName, and
newUserName.
Example 19-2 shows the code for the EventObject class.
// Quit looking.
return true;
}
}
return false;
}
/**
* Returns the complete list of listeners, used during event notification.
*/
public function getListeners ( ):Array {
// Return ...