0% found this document useful (0 votes)
22 views

Java Presentation

Uploaded by

Vishal Shetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Java Presentation

Uploaded by

Vishal Shetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Event Handling in Java

An event can be defined as changing the state of an object o í behavioí by


peífoíming actions.

Actions can be a
● button click
● cuísoí movement
● keypíess thíough keyboaíd
● page scíolling, etc.

The java.awt.event package can be used to píovide vaíious event classes.


EVENTS
FOREGROUND EVENTS BACKGROUND EVENTS

Foreground events are the Events that don’t require


events that require user interactions of users to generate
interaction to generate. are known as background
foreground events are generated events. Examples of these events
due to interaction by the user on are operating system
components in Graphic User failures/interrupts, operation
Interface (GUI). completion, etc
EVENT HANDLING
It is a mechanism to control the events and
to decide what should happen after an event occur.
To handle the events, Java follows the Delegation Event model

WHY EVENT HANDLING IS NEEDED


Event handler code will verify user input and actions as well as browser actions so the
appropriate response occurs every time a page loads, when a page is closed, when a user clicks a
button , when a user inputs data into a form, and so on.
DELEGATION EVENT HANDLING

SOURCES LISTENERS

Events are generated from the They are used for handling the
source. There are various events generated from the
sources like buttons, checkboxes, source. Each of these listeners
list, menu-item, choice, scrollbar represents interfaces that are
to generate events. responsible for handling events.

A source generates an event and sends it to one or more listeners.


In this model, the
listener must be
connected with a
source to receive
the event
notifications.
Thus, the events will
only be received by
the listeners who
wish to receive
them. So, this
approach is more
convenient than the
inheritance-based
event model
● ActionEvent
● AdjustmentEvent
● ComponentEvent
● ContainerEvent
● FocusEvent
● InputEvent
● ItemEvent
● KeyEvent
● MouseEvent
● WindowEvent
● MouseWheelEvent
● TextEvent
Description of Code
ActionEvent: Triggered by button clicks.

AdjustmentEvent: Triggered by scrollbar adjustments.

ComponentEvent: Triggered by component changes (resized, moved, shown,


hidden).

ContainerEvent: Triggered when a component is added to or removed from a


container.

FocusEvent: Triggered when a component gains or loses focus.


ItemEvent: Triggered when an item (like a checkbox) is selected or deselected.

KeyEvent: Triggered by keyboard actions (typed, pressed, released).


MouseEvent: Triggered by mouse actions (click, press, release, enter, exit).

MouseMotionEvent: Triggered by mouse movements (drag, move).

MouseWheelEvent: Triggered by mouse wheel rotations.

TextEvent: Triggered when the text in a text area changes.

WindowEvent: Triggered by window actions (opened, closed, activated,


deactivated).
Expected Output:
● The program logs and displays messages corresponding to
the triggered events.
● Console output and the statusLabel in the UI will show
messages like "MouseEvent: Mouse Clicked", "KeyEvent: Key
Pressed", etc., indicating the type of event that occurred.

You might also like