go to previous page   go to home page   go to next page


Yes. A "listener object" is an object that has listener methods, but it may have other methods.

Event Object

Event Object sent from button to listener

An event listener is an object that "listens" for events from a GUI component, like a button. An event, like a button click, is represented as an object. When the user generates an event, the system creates an event object which is then sent to the listener that has been registered for the GUI component. Then, a method in the listener object is invoked.

To be able to respond to events, a program must:

  1. Create an event listener object for the type of event.
  2. Register the listener object with the GUI component that generates the event (or with a component that contains it).

In the picture, the component is the button, contained in a frame. The user event is a click on that button. An Event object is sent to the registered listener. This is done by the Java system, which manages the GUI components. Now it is the responsibility of the listener to do something in response to the event.


(Thought Question: ) Does the Java system create an Event object every time the user interacts with a component?