Site hosted by Angelfire.com: Build your free website today!
 

Event Object

Every event-listener method has a single argu

ment -- an object that inherits from the EventObject

Although the argument always descends from EventObject, its type is generally specified more precisely. For example, the argument for methods that handle mouse events is an instance of MouseEvent, where MouseEvent is an indirect subclass of EventObject.

The EventObject class defines one very useful method that returns the object that fired the event:

Object getSource()

Event classes sometimes define methods similar to getSource, but that have more restricted return types. For example, the ComponentEvent class defines a getComponent method that -- just like getSource -- returns the object that fired the event. The difference is that getComponent always returns a Component.