100% found this document useful (1 vote)
86 views

Events in Java: Components of Event Handling

Event handling in Java GUI applications has three main components: events, event sources, and listeners. An event is a change in state of an object, like a button click. The event source is the object that generates the event. Listeners are objects that listen for events from sources. When an event occurs, the source notifies any registered listeners, which then process the event. Common events in Java include actions, mouse clicks/movements, keys, items, text, adjustments, windows, and components. Listeners interface with specific event classes like ActionListener, MouseListener, and KeyListener.

Uploaded by

Kellie Lewis
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
86 views

Events in Java: Components of Event Handling

Event handling in Java GUI applications has three main components: events, event sources, and listeners. An event is a change in state of an object, like a button click. The event source is the object that generates the event. Listeners are objects that listen for events from sources. When an event occurs, the source notifies any registered listeners, which then process the event. Common events in Java include actions, mouse clicks/movements, keys, items, text, adjustments, windows, and components. Listeners interface with specific event classes like ActionListener, MouseListener, and KeyListener.

Uploaded by

Kellie Lewis
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1

Events in Java
Event Handling
Any program that uses GUI (graphical user interface) such as Java application written for
windows, is event driven. Event describes the change of state of any object. Example : Pressing a
button, Entering a character in Textbox.
Components of Event Handling
Event handling has three main components-
1-Events : An event is a change of state of an object.
2-Events Source : Event source is an object that generates an event.
3-Listeners : A listener is an object that listens to the event. A listener gets notified when an
event occurs.
How Events are handled ?
A source generates an Event and send it to one or more listeners registered with the source.
Once event is received by the listener, they processe the event and then return. Events are
supported by a number of Java packages, like java.util, java.awt and java.awt.event.
Event classes and Listener interfaces:
Event Classes Listener Interfaces
ActionEvent ActionListener
MouseEvent MouseListener and MouseMotionListener
MouseWheelEvent MouseWheelListener
KeyEvent KeyListener
ItemEvent ItemListener
TextEvent TextListener
AdjustmentEvent AdjustmentListener
WindowEvent WindowListener
ComponentEvent ComponentListener
ContainerEvent ContainerListener
FocusEvent FocusListener

2

For registering the component with the Listener, many classes provide the registration
methods. For example:-
Button
o public void addActionListener(ActionListener a){}
MenuItem
o public void addActionListener(ActionListener a){}
TextField
o public void addActionListener(ActionListener a){}
o public void addTextListener(TextListener a){}
TextArea
o public void addTextListener(TextListener a){}
Checkbox
o public void addItemListener(ItemListener a){}
Choice
o public void addItemListener(ItemListener a){}
List
o public void addActionListener(ActionListener a){}
o public void addItemListener(ItemListener a){}

You might also like