Working with event handling
? An object that describes a change of state in a source component is called
? The source components can be the elements of the Graphical User Interface(GUI).
? Events are supported by the classes and interfaces defined in the 'java.awt.event' package.
? Identifying the Source Of Events:
? An event source is an object that generates an event.
? An event source registers some listeners, which receive notifications about a specific type of event generated by that particular event source.
? All the registered listeners are notified about the generation of an event and receive a copy of the event object.
? This is known as multicasting the event.
? Some sources allow only single listener to register.
? This is known as unicasting of event.
Given below various event sources and the types of events they generate :
|Checkbox||Creates an item event when a check
box is selected or deselected.
|Button||Creates an action event when a
button is pressed.
|List||Creates an action event when an item
is double-clicked; creates an item
event when an item is selected or
|Scrollbar||Creates an adjustment event when
a scroll bar is scrolled.
|Text components||Creates a text event when a text
character is entered in the text
|Window||Creates a window event when a
window is activated, deactivated,
opened, closed, or quit.
Event Listeners and Event Handlers
? An event listener listens for a specific event and is notified when that
specific event occurs.
? An event listener registers with one or more event sources to receive notifications about specific types of events and processes the events.
? An event-handler is called by the event listener whenever a specific event occurs.
? Event listeners are interfaces and the event-handler is a method declared in the event listener interface that is implemented by the application.
? The syntax of a method that registers an event listener with an event source is:
public void addTYPEListener(TYPEListener obj)