Event Handling in Java
Event :
An event is an Object that describes a
state change in a Source.
* Some of the activities that causes event
to be generated are :
*Pressing a Button.
*Entering a character through
Key Board.
*Selecting an item form a list etc.
Event Handling in Java
Event Handling in Java
 For implementing event listener we have to
import the following Statement:
import java.awt.event.*;
 Event Handling is the mechanism that
controls the event and decides what should
happen if an event occurs.This mechanism
have the code which is known as event
handler that is executed when an event
occurs. Java Uses the Delegation Event
Model to handle the events.This model
defines the standard mechanism to
generate and handle the events
 Foreground Events:
Those events which require
the direct interaction of user.They are
generated as consequences of a person
interacting with the graphical components in
Graphical User Interface. For example, clicking
on a button, moving the mouse, entering a
character through keyboard,selecting an item
from list, scrolling the page etc.
 Background Events :
Those events that require
the interaction of end user are known as
background events. Operating system
interrupts, hardware or software failure,
timer expires, an operation completion are
the example of background events.
Event Handling in Java
 Input events:
 Input events generally carry three pieces of
information: the event type, the location of
the mouse or pen when the event occurred,
and some modifier button information.The
modifier information includes which
mouse/pen buttons are currently pressed
and whether control, shift, alt or command
keys are also pressed at the time.
 Key events:
 The component peers deliver separate key
events when a user presses and releases
nearly any key. KEY_ACTION and
KEY_ACTION_RELEASE are for the
function and arrow keys, while KEY_PRESS
and KEY_RELEASE are for the remaining
control and alphanumeric keys.
 Mouse events
 The component peers deliver mouse events
when a user presses or releases a mouse
button. Events are also delivered whenever
the mouse moves.
 For example :
 MouseMotionListener interface
define two events:
 When mouse is dragged.
 When mouse is moved.
 Focus events
 The peers deliver focus events when a
component gains (GOT_FOCUS) or
loses(LOST_FOCUS) the input focus. No
default methods are called for the focus
events. They must be dealt with in the
handleEvent() method of the Container of
the component or a subclass of the
component.
 ActionEvent
 The ActionEvent class is the first higher-
level event class. It encapsulates events
that signify that the user is doing
something with a component.When the
user selects a button, list item, or menu
item, or presses the Return key in a text
field, an ActionEvent passes through the
event queue looking for listeners.
 ItemEvent:
 The ItemEvent class is another higher-level
event class. It encapsulates events that occur
when the user selects a component, like
ActionEvent. When the user selects a
checkbox, choice, list item, or checkbox menu
item, an ItemEvent passes through the event
queue looking for listeners. Although there is
only one type of ItemEvent, there are two
subtypes represented by the constants
SELECTED and DE- SELECTED.
 It is simple and well suited to an object-
oriented programming environment.
► An event can only be handled by the
component from which it originated or by
one of the containers of the originating
component.
►In order to handle events, you must either
subclass the component that receives the
event or create a handleEvent() method at
the base container.
 A delegate is better adapted to an object-
oriented language model and is completely
type checked for code reliability.
 Source -The source is an object on which
event occurs. Source is responsible for
providing information of the occurred
event to it's handler. Java provide as with
classes for source object.
 Listener - It is also known as event handler.
Listener is responsible for generating
response to an event.The listener is also an
object. Listener waits until it receives an
event. Once the event is received , the
listener process the event an then returns.
 The User clicks the button and the event is
generated.
 Now the object of concerned event class is
created automatically and information
about the source and the event get
populated with in same object.
 Event object is forwarded to the method of
registered listener class.
 the method is now get executed and
returns.
 In order to design a listener class we have
to develop some listener interfaces.These
Listener interfaces forecast some public
abstract callback methods which must be
implemented by the listener class.
 If you do not implement the any if the
predefined interfaces then your class can
not act as a listener class for a source
object.
 The callback methods represents an event
method. In response to an event java jre
will fire callback method. All such callback
methods are provided in listener interfaces.
Why use Adapter classes?
 Implementing all methods of an interface
takes a lot of work
 Interested in implementing some methods
of the interface only.
 Built-in in Java
 Implement all methods of each listener
interface
 with more than one method.
 Making Simple Calculators By Using Event
Handling:
Event Handling in Java

More Related Content

PPTX
Event Handling in java
PPS
Wrapper class
PPTX
Exception handling in java
PPTX
JAVA AWT
PPT
Java awt
PPTX
Constructor in java
PDF
Strings in java
PPTX
Vectors in Java
Event Handling in java
Wrapper class
Exception handling in java
JAVA AWT
Java awt
Constructor in java
Strings in java
Vectors in Java

What's hot (20)

PPTX
Event Handling in JAVA
PDF
Asp.net state management
PPT
Java: GUI
PPT
Java adapter
PPTX
java interface and packages
PPTX
Classes objects in java
PPT
Exception Handling in JAVA
PPTX
Java string handling
PPTX
Event handling
PPTX
Regular expressions in Python
PPTX
Java swing
PPT
Swing and AWT in java
PPT
Class 5 - PHP Strings
PPTX
SWING USING JAVA WITH VARIOUS COMPONENTS
PPT
9. Input Output in java
PDF
Run time storage
PDF
PPTX
Java awt (abstract window toolkit)
Event Handling in JAVA
Asp.net state management
Java: GUI
Java adapter
java interface and packages
Classes objects in java
Exception Handling in JAVA
Java string handling
Event handling
Regular expressions in Python
Java swing
Swing and AWT in java
Class 5 - PHP Strings
SWING USING JAVA WITH VARIOUS COMPONENTS
9. Input Output in java
Run time storage
Java awt (abstract window toolkit)
Ad

Viewers also liked (17)

PPTX
Java programming-Event Handling
PPTX
tL20 event handling
PPT
Java Event Handling
PDF
Basic Event Listener
PPTX
Event handling
PPT
๋Java Programming [7/12] : GUI Event Handling
PPT
Learning Java 4 – Swing, SQL, and Security API
PPTX
Java 8 parallel stream
PPS
Java session11
PDF
Concurrency Utilities in Java 8
PDF
Java 8 Stream API. A different way to process collections.
PPT
Learning Java 3 – Threads and Synchronization
PDF
Working With Concurrency In Java 8
PDF
Java Thread Synchronization
PPT
Java 8 Streams
PPTX
PPTX
Java programming-Event Handling
tL20 event handling
Java Event Handling
Basic Event Listener
Event handling
๋Java Programming [7/12] : GUI Event Handling
Learning Java 4 – Swing, SQL, and Security API
Java 8 parallel stream
Java session11
Concurrency Utilities in Java 8
Java 8 Stream API. A different way to process collections.
Learning Java 3 – Threads and Synchronization
Working With Concurrency In Java 8
Java Thread Synchronization
Java 8 Streams
Ad

Similar to Event Handling in Java (20)

PPTX
Event handling in Java(part 1)
PPT
Unit 6 Java
PDF
Ajp notes-chapter-03
PDF
Event Handling in Java as per university
PPTX
What is Event
PPTX
Advance java programming- Event handling
PPTX
ITE 1122_ Event Handling.pptx
PPTX
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
PPTX
Advance Java Programming(CM5I) Event handling
PDF
Java Programming :Event Handling(Types of Events)
PPT
Java gui event
PPTX
EVENT HANDLING in Object Oriented Programming in Java
PPTX
event-handling.pptx
PDF
Unit-3 event handling
PPT
event handling new.ppt
PPTX
Chap - 2 - Event Handling.pptx
PPT
Unit 5.133333333333333333333333333333333.ppt
DOCX
Dr Jammi Ashok - Introduction to Java Material (OOPs)
PPT
engineeringdsgtnotesofunitfivesnists.ppt
Event handling in Java(part 1)
Unit 6 Java
Ajp notes-chapter-03
Event Handling in Java as per university
What is Event
Advance java programming- Event handling
ITE 1122_ Event Handling.pptx
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
Advance Java Programming(CM5I) Event handling
Java Programming :Event Handling(Types of Events)
Java gui event
EVENT HANDLING in Object Oriented Programming in Java
event-handling.pptx
Unit-3 event handling
event handling new.ppt
Chap - 2 - Event Handling.pptx
Unit 5.133333333333333333333333333333333.ppt
Dr Jammi Ashok - Introduction to Java Material (OOPs)
engineeringdsgtnotesofunitfivesnists.ppt

Recently uploaded (20)

PDF
Canva Desktop App With Crack Free Download 2025?
PDF
Top 10 Project Management Software for Small Teams in 2025.pdf
PPTX
Improving Audience Engagement ROI with ERP-Powered Insights
PPTX
MCP empowers AI Agents from Zero to Production
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PDF
OpenTimelineIO Virtual Town Hall - August 2025
PDF
Top AI Tools for Project Managers: My 2025 AI Stack
PDF
DOWNLOAD—IOBit Uninstaller Pro Crack Download Free
PPTX
Presentation - Summer Internship at Samatrix.io_template_2.pptx
PPTX
ESDS_SAP Application Cloud Offerings.pptx
PPTX
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx
PPTX
AI Tools Revolutionizing Software Development Workflows
PDF
OpenColorIO Virtual Town Hall - August 2025
PDF
Module 1 - Introduction to Generative AI.pdf
PPTX
Comprehensive Guide to Digital Image Processing Concepts and Applications
PPTX
Lesson-3-Operation-System-Support.pptx-I
PDF
10 Mistakes Agile Project Managers Still Make
PDF
solman-7.0-ehp1-sp21-incident-management
PPTX
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
PDF
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf
Canva Desktop App With Crack Free Download 2025?
Top 10 Project Management Software for Small Teams in 2025.pdf
Improving Audience Engagement ROI with ERP-Powered Insights
MCP empowers AI Agents from Zero to Production
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
OpenTimelineIO Virtual Town Hall - August 2025
Top AI Tools for Project Managers: My 2025 AI Stack
DOWNLOAD—IOBit Uninstaller Pro Crack Download Free
Presentation - Summer Internship at Samatrix.io_template_2.pptx
ESDS_SAP Application Cloud Offerings.pptx
StacksandQueuesCLASS 12 COMPUTER SCIENCE.pptx
AI Tools Revolutionizing Software Development Workflows
OpenColorIO Virtual Town Hall - August 2025
Module 1 - Introduction to Generative AI.pdf
Comprehensive Guide to Digital Image Processing Concepts and Applications
Lesson-3-Operation-System-Support.pptx-I
10 Mistakes Agile Project Managers Still Make
solman-7.0-ehp1-sp21-incident-management
Post-Migration Optimization Playbook: Getting the Most Out of Your New Adobe ...
Multiverse AI Review 2025_ The Ultimate All-in-One AI Platform.pdf

Event Handling in Java

  • 2. Event : An event is an Object that describes a state change in a Source. * Some of the activities that causes event to be generated are : *Pressing a Button. *Entering a character through Key Board. *Selecting an item form a list etc.
  • 5.  For implementing event listener we have to import the following Statement: import java.awt.event.*;
  • 6.  Event Handling is the mechanism that controls the event and decides what should happen if an event occurs.This mechanism have the code which is known as event handler that is executed when an event occurs. Java Uses the Delegation Event Model to handle the events.This model defines the standard mechanism to generate and handle the events
  • 7.  Foreground Events: Those events which require the direct interaction of user.They are generated as consequences of a person interacting with the graphical components in Graphical User Interface. For example, clicking on a button, moving the mouse, entering a character through keyboard,selecting an item from list, scrolling the page etc.
  • 8.  Background Events : Those events that require the interaction of end user are known as background events. Operating system interrupts, hardware or software failure, timer expires, an operation completion are the example of background events.
  • 10.  Input events:  Input events generally carry three pieces of information: the event type, the location of the mouse or pen when the event occurred, and some modifier button information.The modifier information includes which mouse/pen buttons are currently pressed and whether control, shift, alt or command keys are also pressed at the time.
  • 11.  Key events:  The component peers deliver separate key events when a user presses and releases nearly any key. KEY_ACTION and KEY_ACTION_RELEASE are for the function and arrow keys, while KEY_PRESS and KEY_RELEASE are for the remaining control and alphanumeric keys.
  • 12.  Mouse events  The component peers deliver mouse events when a user presses or releases a mouse button. Events are also delivered whenever the mouse moves.
  • 13.  For example :  MouseMotionListener interface define two events:  When mouse is dragged.  When mouse is moved.
  • 14.  Focus events  The peers deliver focus events when a component gains (GOT_FOCUS) or loses(LOST_FOCUS) the input focus. No default methods are called for the focus events. They must be dealt with in the handleEvent() method of the Container of the component or a subclass of the component.
  • 15.  ActionEvent  The ActionEvent class is the first higher- level event class. It encapsulates events that signify that the user is doing something with a component.When the user selects a button, list item, or menu item, or presses the Return key in a text field, an ActionEvent passes through the event queue looking for listeners.
  • 16.  ItemEvent:  The ItemEvent class is another higher-level event class. It encapsulates events that occur when the user selects a component, like ActionEvent. When the user selects a checkbox, choice, list item, or checkbox menu item, an ItemEvent passes through the event queue looking for listeners. Although there is only one type of ItemEvent, there are two subtypes represented by the constants SELECTED and DE- SELECTED.
  • 17.  It is simple and well suited to an object- oriented programming environment.
  • 18. ► An event can only be handled by the component from which it originated or by one of the containers of the originating component. ►In order to handle events, you must either subclass the component that receives the event or create a handleEvent() method at the base container.
  • 19.  A delegate is better adapted to an object- oriented language model and is completely type checked for code reliability.
  • 20.  Source -The source is an object on which event occurs. Source is responsible for providing information of the occurred event to it's handler. Java provide as with classes for source object.
  • 21.  Listener - It is also known as event handler. Listener is responsible for generating response to an event.The listener is also an object. Listener waits until it receives an event. Once the event is received , the listener process the event an then returns.
  • 22.  The User clicks the button and the event is generated.  Now the object of concerned event class is created automatically and information about the source and the event get populated with in same object.  Event object is forwarded to the method of registered listener class.  the method is now get executed and returns.
  • 23.  In order to design a listener class we have to develop some listener interfaces.These Listener interfaces forecast some public abstract callback methods which must be implemented by the listener class.  If you do not implement the any if the predefined interfaces then your class can not act as a listener class for a source object.
  • 24.  The callback methods represents an event method. In response to an event java jre will fire callback method. All such callback methods are provided in listener interfaces.
  • 25. Why use Adapter classes?  Implementing all methods of an interface takes a lot of work  Interested in implementing some methods of the interface only.
  • 26.  Built-in in Java  Implement all methods of each listener interface  with more than one method.  Making Simple Calculators By Using Event Handling: