SlideShare a Scribd company logo
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

What's hot (20)

PPTX
Java Swing
Arkadeep Dey
 
PPT
Swing and AWT in java
Adil Mehmoood
 
PPTX
Android User Interface
Shakib Hasan Sumon
 
PPT
Android - Android Intent Types
Vibrant Technologies & Computers
 
PPTX
jQuery
Jay Poojara
 
PPT
Java: GUI
Tareq Hasan
 
PPTX
Event handling
Anand Grewal
 
PPTX
Java swing
Apurbo Datta
 
PDF
jQuery for beginners
Arulmurugan Rajaraman
 
PPTX
Windowforms controls c#
prabhu rajendran
 
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
PPT
Java Servlets
BG Java EE Course
 
PPTX
Inheritance, friend function, virtual function, polymorphism
Jawad Khan
 
PPTX
Threads in JAVA
Haldia Institute of Technology
 
PPTX
Applets in java
Wani Zahoor
 
PPT
Java awt
Arati Gadgil
 
PPTX
Vectors in Java
Abhilash Nair
 
PPTX
Java Beans
Ankit Desai
 
PPTX
I/O Streams
Ravi Chythanya
 
PPTX
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 
Java Swing
Arkadeep Dey
 
Swing and AWT in java
Adil Mehmoood
 
Android User Interface
Shakib Hasan Sumon
 
Android - Android Intent Types
Vibrant Technologies & Computers
 
jQuery
Jay Poojara
 
Java: GUI
Tareq Hasan
 
Event handling
Anand Grewal
 
Java swing
Apurbo Datta
 
jQuery for beginners
Arulmurugan Rajaraman
 
Windowforms controls c#
prabhu rajendran
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
Java Servlets
BG Java EE Course
 
Inheritance, friend function, virtual function, polymorphism
Jawad Khan
 
Applets in java
Wani Zahoor
 
Java awt
Arati Gadgil
 
Vectors in Java
Abhilash Nair
 
Java Beans
Ankit Desai
 
I/O Streams
Ravi Chythanya
 
Abstract Class & Abstract Method in Core Java
MOHIT AGARWAL
 

Viewers also liked (15)

PPTX
Java programming-Event Handling
Java Programming
 
PPTX
tL20 event handling
teach4uin
 
PPT
Java Event Handling
Shraddha
 
PDF
Basic Event Listener
kunemata
 
PPT
๋Java Programming [7/12] : GUI Event Handling
IMC Institute
 
PPT
Learning Java 4 – Swing, SQL, and Security API
caswenson
 
PPTX
Java 8 parallel stream
Yung Chieh Tsai
 
PPS
Java session11
Niit Care
 
PDF
Concurrency Utilities in Java 8
Martin Toshev
 
PDF
Java 8 Stream API. A different way to process collections.
David Gómez García
 
PPT
Learning Java 3 – Threads and Synchronization
caswenson
 
PDF
Working With Concurrency In Java 8
Heartin Jacob
 
PDF
Java Thread Synchronization
Benj Del Mundo
 
PPT
Java 8 Streams
Manvendra Singh
 
PPTX
Awt
Rakesh Patil
 
Java programming-Event Handling
Java Programming
 
tL20 event handling
teach4uin
 
Java Event Handling
Shraddha
 
Basic Event Listener
kunemata
 
๋Java Programming [7/12] : GUI Event Handling
IMC Institute
 
Learning Java 4 – Swing, SQL, and Security API
caswenson
 
Java 8 parallel stream
Yung Chieh Tsai
 
Java session11
Niit Care
 
Concurrency Utilities in Java 8
Martin Toshev
 
Java 8 Stream API. A different way to process collections.
David Gómez García
 
Learning Java 3 – Threads and Synchronization
caswenson
 
Working With Concurrency In Java 8
Heartin Jacob
 
Java Thread Synchronization
Benj Del Mundo
 
Java 8 Streams
Manvendra Singh
 
Ad

Similar to Event Handling in Java (20)

PPTX
What is Event
Asmita Prasad
 
PPT
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
sangeethajadhav9901
 
PPTX
Advance java programming- Event handling
vidyamali4
 
PPTX
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
PPTX
ITE 1122_ Event Handling.pptx
udithaisur
 
PPT
Chapter 8 event Handling.ppt m m m m m m
zmulani8
 
PPTX
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
 
PPTX
event-handling.pptx
usvirat1805
 
PPT
Java gui event
SoftNutx
 
PDF
java-programming GUI- Event Handling.pdf
doraeshin04
 
PPTX
UNIT III Event Handling of the car j.pptx
CISCONETWORKING
 
PDF
Java Programming :Event Handling(Types of Events)
simmis5
 
PPTX
EVENT HANDLING in Object Oriented Programming in Java
marysj3
 
PPTX
Module3.11.pptx
VeenaNaik23
 
PPT
Unit 6 Java
arnold 7490
 
PDF
Event handling
Ravi_Kant_Sahu
 
PDF
Event handling
Ravi Kant Sahu
 
PPTX
Module 5.pptx
VeenaNaik23
 
PPT
Events1
Nuha Noor
 
PPTX
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
What is Event
Asmita Prasad
 
unit-6.pptbjjdjdkd ndmdkjdjdjjdkfjjfjfjfj
sangeethajadhav9901
 
Advance java programming- Event handling
vidyamali4
 
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
ITE 1122_ Event Handling.pptx
udithaisur
 
Chapter 8 event Handling.ppt m m m m m m
zmulani8
 
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
 
event-handling.pptx
usvirat1805
 
Java gui event
SoftNutx
 
java-programming GUI- Event Handling.pdf
doraeshin04
 
UNIT III Event Handling of the car j.pptx
CISCONETWORKING
 
Java Programming :Event Handling(Types of Events)
simmis5
 
EVENT HANDLING in Object Oriented Programming in Java
marysj3
 
Module3.11.pptx
VeenaNaik23
 
Unit 6 Java
arnold 7490
 
Event handling
Ravi_Kant_Sahu
 
Event handling
Ravi Kant Sahu
 
Module 5.pptx
VeenaNaik23
 
Events1
Nuha Noor
 
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
Ad

Recently uploaded (20)

PDF
Transparency into Your Software’s True Reach
team-WIBU
 
PDF
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
PDF
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
 
PPTX
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
PDF
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
PPTX
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
PPTX
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
PPTX
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
PDF
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PDF
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Transparency into Your Software’s True Reach
team-WIBU
 
LPS25 - Operationalizing MLOps in GEP - Terradue.pdf
terradue
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
Capcut Pro Crack For PC Latest Version {Fully Unlocked} 2025
hashhshs786
 
capitulando la keynote de GrafanaCON 2025 - Madrid
Imma Valls Bernaus
 
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
 
IObit Uninstaller Pro 14.3.1.8 Crack Free Download 2025
sdfger qwerty
 
AWS Consulting Services: Empowering Digital Transformation with Nlineaxis
Nlineaxis IT Solutions Pvt Ltd
 
Iobit Driver Booster Pro 12 Crack Free Download
chaudhryakashoo065
 
NeuroStrata: Harnessing Neuro-Symbolic Paradigms for Improved Testability and...
Ivan Ruchkin
 
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
Designing Accessible Content Blocks (1).pdf
jaclynmennie1
 
Dealing with JSON in the relational world
Andres Almiray
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
Difference Between Kubernetes and Docker .pdf
Kindlebit Solutions
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 

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: