SlideShare a Scribd company logo
3
Most read
4
Most read
5
Most read
Event Handling
Simmi S
Department of Computer Science(UG)
Kristu Jayanti College , Bangalore
 Event handling is fundamental to Java programming because
it is used to create event driven programs eg
Applets
GUI based windows application
Web Application
 Event handling mechanism have been changed
significantly between the original version of Java (1.0) and all
subsequent versions of Java, beginning with version 1.1.
 The modern approach to handling events is based on the
delegation event model,
Event Handling
What is an Event?
 Change in the state of an object is known as event i.e. event describes the
change in state of source.
 Events are generated as result of user interaction with the graphical user
interface components.
 For example, clicking on a button, moving the mouse, entering a character
through keyboard, selecting an item from list, scrolling the page are the
activities that causes an event to happen.
Types of Event
 The events can be broadly classified into two categories:
 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 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. Let's have a brief introduction to this model.
What is Event Handling?
Source & Listener
The Delegation Event Model has the following key participants namely:
 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 provides classes for source object.
 Listener - It is also known as event handler.
 Listener is responsible for generating response to an event. From
java implementation point of view 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.
Source & Listener
 Its concept is quite simple: a source generates an event and sends it to one or
more listeners. In this scheme, the listener simply waits until it receives an event.
 Once an event is received, the listener processes the event and then returns.
 This provides an important benefit: notifications are sent only to listeners that
want to receive them.
 To perform Event Handling, we need to register the source with the listener.
Registering Listener
 A source must register listeners in order for the listeners to receive
notifications about a specific type of event. Each type of event has its own
registration method. Here is the general form:
public void addTypeListener (TypeListener el)
 Type is the name of the event, and el is a reference to the event listener.
 For example, the method that registers a keyboard event listener is called
addKeyListener( ). The method that registers a mouse motion listener is called
addMouseMotionListener( ).
Delegation Event Model
Event Classes in Java
Event Classes in Java
Event Classes in Java
Event Listener Interfaces
 As explained, the delegation event model has two parts: sources and
listeners.
 Listeners are created by implementing one or more of the interfaces
defined by the java.awt.event package.
 When an event occurs, the event source invokes the appropriate method
defined by the listener and provides an event object as its argument
Event Listener Interfaces
Listener Interface Methods
ActionListener •actionPerformed()
AdjustmentListener •adjustmentValueChanged()
ComponentListener
•componentResized()
•componentShown()
•componentMoved()
•componentHidden()
ContainerListener
•componentAdded()
•componentRemoved()
FocusListener
•focusGained()
•focusLost()
Event Listener Interfaces
ItemListener •itemStateChanged()
KeyListener
•keyTyped()
•keyPressed()
•keyReleased()
MouseListener
•mousePressed()
•mouseClicked()
•mouseEntered()
•mouseExited()
•mouseReleased()
MouseMotionListener
•mouseMoved()
•mouseDragged()
MouseWheelListener •mouseWheelMoved()
Java MouseListener Interface
 The Java MouseListener is notified whenever you change the state of
mouse. It is notified against MouseEvent.
 The MouseListener interface is found in java.awt.event package. It
has five methods
Methods of MouseListener interface
 The signature of 5 methods found in MouseListener interface are given
below:
 public abstract void mouseClicked(MouseEvent e);
 public abstract void mouseEntered(MouseEvent e);
 public abstract void mouseExited(MouseEvent e);
 public abstract void mousePressed(MouseEvent e);
 public abstract void mouseReleased(MouseEvent e);
MouseListener Sample Program
Java Programming :Event Handling(Types of Events)
Java KeyListener Interface
 The Java KeyListener is notified whenever you change the state
of key.
 It is notified against KeyEvent. The KeyListener interface is found
in java.awt.event package, and it has three methods
Interface declaration
 Following is the declaration
for java.awt.event.KeyListener interface:
 public interface KeyListener extends EventListener
Sr. no. Method name Description
1. public abstract void
keyPressed (KeyEvent e);
It is invoked when a key has
been pressed.
2. public abstract void
keyReleased (KeyEvent e);
It is invoked when a key has
been released.
3. public abstract void keyTyped
(KeyEvent e);
It is invoked when a key has
been typed
THANK YOU

More Related Content

What's hot (20)

PDF
Major and Minor Elements of Object Model
sohailsaif
 
PPTX
Event handling
swapnac12
 
PPT
Java Servlets
BG Java EE Course
 
PPT
Coupling and cohesion
Sutha31
 
PPTX
Image compression models
priyadharshini murugan
 
PDF
Asp .net web form fundamentals
Gopal Ji Singh
 
PDF
Servlet and servlet life cycle
Dhruvin Nakrani
 
PPTX
graphics programming in java
Abinaya B
 
PPTX
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
PPTX
Finite Automata in compiler design
Riazul Islam
 
PDF
The Object Model
yndaravind
 
PPTX
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
Aaqib Hussain
 
PPTX
JAVA AWT
shanmuga rajan
 
PDF
Sequence diagram- UML diagram
Ramakant Soni
 
PPTX
Computer graphics chapter 4
PrathimaBaliga
 
PPSX
ADO.NET
Farzad Wadia
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPT
Object Oriented Design in Software Engineering SE12
koolkampus
 
PPT
State Machine Diagram
Niloy Rocker
 
PPTX
Image Enhancement in Spatial Domain
DEEPASHRI HK
 
Major and Minor Elements of Object Model
sohailsaif
 
Event handling
swapnac12
 
Java Servlets
BG Java EE Course
 
Coupling and cohesion
Sutha31
 
Image compression models
priyadharshini murugan
 
Asp .net web form fundamentals
Gopal Ji Singh
 
Servlet and servlet life cycle
Dhruvin Nakrani
 
graphics programming in java
Abinaya B
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Finite Automata in compiler design
Riazul Islam
 
The Object Model
yndaravind
 
INTRODUCTION TO JSP,JSP LIFE CYCLE, ANATOMY OF JSP PAGE AND JSP PROCESSING
Aaqib Hussain
 
JAVA AWT
shanmuga rajan
 
Sequence diagram- UML diagram
Ramakant Soni
 
Computer graphics chapter 4
PrathimaBaliga
 
ADO.NET
Farzad Wadia
 
Data Types & Variables in JAVA
Ankita Totala
 
Object Oriented Design in Software Engineering SE12
koolkampus
 
State Machine Diagram
Niloy Rocker
 
Image Enhancement in Spatial Domain
DEEPASHRI HK
 

Similar to Java Programming :Event Handling(Types of Events) (20)

PPTX
EVENT HANDLING in Object Oriented Programming in Java
marysj3
 
PPTX
Advance java programming- Event handling
vidyamali4
 
PPTX
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
PPTX
Event Handling in Java
Ayesha Kanwal
 
PPTX
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
PPTX
ITE 1122_ Event Handling.pptx
udithaisur
 
PPTX
event-handling.pptx
usvirat1805
 
PDF
Ajp notes-chapter-03
Ankit Dubey
 
PPTX
Event handling in Java(part 1)
RAJITHARAMACHANDRAN1
 
PDF
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
PDF
Event Handling in Java as per university
Sanjay Kumar
 
PPTX
Event Handling in JAVA
Srajan Shukla
 
PPTX
PROGRAMMING IN JAVA- unit 4-part II
SivaSankari36
 
PPTX
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
 
PDF
Event handling
Ravi_Kant_Sahu
 
PDF
Event handling
Ravi Kant Sahu
 
PPT
Events1
Nuha Noor
 
PPT
Unit 6 Java
arnold 7490
 
PDF
JAVA GUI PART III
OXUS 20
 
EVENT HANDLING in Object Oriented Programming in Java
marysj3
 
Advance java programming- Event handling
vidyamali4
 
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
Event Handling in Java
Ayesha Kanwal
 
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
ITE 1122_ Event Handling.pptx
udithaisur
 
event-handling.pptx
usvirat1805
 
Ajp notes-chapter-03
Ankit Dubey
 
Event handling in Java(part 1)
RAJITHARAMACHANDRAN1
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
Event Handling in Java as per university
Sanjay Kumar
 
Event Handling in JAVA
Srajan Shukla
 
PROGRAMMING IN JAVA- unit 4-part II
SivaSankari36
 
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
 
Event handling
Ravi_Kant_Sahu
 
Event handling
Ravi Kant Sahu
 
Events1
Nuha Noor
 
Unit 6 Java
arnold 7490
 
JAVA GUI PART III
OXUS 20
 
Ad

More from simmis5 (11)

PPTX
Software reuse is the use of existing artifacts to build new software compone...
simmis5
 
PPTX
Unified Modeling Language in Software Engineering
simmis5
 
PDF
JAVA SWING:Swing is a Java Foundation Classes [JFC] library and an extension ...
simmis5
 
PDF
The Concept of Abstract Window Took Kit In Java
simmis5
 
PDF
Software Engineering :Project Management
simmis5
 
PDF
The Concept Of Multithreading In Java Programming
simmis5
 
PDF
Conditional Statements & Loops
simmis5
 
PDF
STRING HANDLING FUNCTIONS.pdf
simmis5
 
PDF
Multiplexer.pdf
simmis5
 
PDF
Encoder_decoder_si.pdf
simmis5
 
PDF
c_algo_flowchart.pdf
simmis5
 
Software reuse is the use of existing artifacts to build new software compone...
simmis5
 
Unified Modeling Language in Software Engineering
simmis5
 
JAVA SWING:Swing is a Java Foundation Classes [JFC] library and an extension ...
simmis5
 
The Concept of Abstract Window Took Kit In Java
simmis5
 
Software Engineering :Project Management
simmis5
 
The Concept Of Multithreading In Java Programming
simmis5
 
Conditional Statements & Loops
simmis5
 
STRING HANDLING FUNCTIONS.pdf
simmis5
 
Multiplexer.pdf
simmis5
 
Encoder_decoder_si.pdf
simmis5
 
c_algo_flowchart.pdf
simmis5
 
Ad

Recently uploaded (20)

PDF
Tesia Dobrydnia - An Avid Hiker And Backpacker
Tesia Dobrydnia
 
PDF
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
PPTX
L300 Technical Slide Library_Feb 2025 microsoft purview
macarenabenitez6
 
PDF
Authentication Devices in Fog-mobile Edge Computing Environments through a Wi...
ijujournal
 
PDF
this idjfk sgfdhgdhgdbhgbgrbdrwhrgbbhtgdt
WaleedAziz7
 
PDF
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
PDF
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
PDF
Bayesian Learning - Naive Bayes Algorithm
Sharmila Chidaravalli
 
PPTX
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PDF
NTPC PATRATU Summer internship report.pdf
hemant03701
 
PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PPTX
Functions in Python Programming Language
BeulahS2
 
PPTX
Precooling and Refrigerated storage.pptx
ThongamSunita
 
PDF
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PDF
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
DOCX
Engineering Geology Field Report to Malekhu .docx
justprashant567
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
Tesia Dobrydnia - An Avid Hiker And Backpacker
Tesia Dobrydnia
 
Submit Your Papers-International Journal on Cybernetics & Informatics ( IJCI)
IJCI JOURNAL
 
L300 Technical Slide Library_Feb 2025 microsoft purview
macarenabenitez6
 
Authentication Devices in Fog-mobile Edge Computing Environments through a Wi...
ijujournal
 
this idjfk sgfdhgdhgdbhgbgrbdrwhrgbbhtgdt
WaleedAziz7
 
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
NFPA 10 - Estandar para extintores de incendios portatiles (ed.22 ENG).pdf
Oscar Orozco
 
Bayesian Learning - Naive Bayes Algorithm
Sharmila Chidaravalli
 
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
NTPC PATRATU Summer internship report.pdf
hemant03701
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
Functions in Python Programming Language
BeulahS2
 
Precooling and Refrigerated storage.pptx
ThongamSunita
 
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
LLC CM NCP1399 SIMPLIS MODEL MANUAL.PDF
ssuser1be9ce
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
Engineering Geology Field Report to Malekhu .docx
justprashant567
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 

Java Programming :Event Handling(Types of Events)

  • 1. Event Handling Simmi S Department of Computer Science(UG) Kristu Jayanti College , Bangalore
  • 2.  Event handling is fundamental to Java programming because it is used to create event driven programs eg Applets GUI based windows application Web Application  Event handling mechanism have been changed significantly between the original version of Java (1.0) and all subsequent versions of Java, beginning with version 1.1.  The modern approach to handling events is based on the delegation event model, Event Handling
  • 3. What is an Event?  Change in the state of an object is known as event i.e. event describes the change in state of source.  Events are generated as result of user interaction with the graphical user interface components.  For example, clicking on a button, moving the mouse, entering a character through keyboard, selecting an item from list, scrolling the page are the activities that causes an event to happen.
  • 4. Types of Event  The events can be broadly classified into two categories:  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.
  • 5.  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. Let's have a brief introduction to this model. What is Event Handling?
  • 6. Source & Listener The Delegation Event Model has the following key participants namely:  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 provides classes for source object.  Listener - It is also known as event handler.  Listener is responsible for generating response to an event. From java implementation point of view 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.
  • 7. Source & Listener  Its concept is quite simple: a source generates an event and sends it to one or more listeners. In this scheme, the listener simply waits until it receives an event.  Once an event is received, the listener processes the event and then returns.  This provides an important benefit: notifications are sent only to listeners that want to receive them.  To perform Event Handling, we need to register the source with the listener.
  • 8. Registering Listener  A source must register listeners in order for the listeners to receive notifications about a specific type of event. Each type of event has its own registration method. Here is the general form: public void addTypeListener (TypeListener el)  Type is the name of the event, and el is a reference to the event listener.  For example, the method that registers a keyboard event listener is called addKeyListener( ). The method that registers a mouse motion listener is called addMouseMotionListener( ).
  • 13. Event Listener Interfaces  As explained, the delegation event model has two parts: sources and listeners.  Listeners are created by implementing one or more of the interfaces defined by the java.awt.event package.  When an event occurs, the event source invokes the appropriate method defined by the listener and provides an event object as its argument
  • 14. Event Listener Interfaces Listener Interface Methods ActionListener •actionPerformed() AdjustmentListener •adjustmentValueChanged() ComponentListener •componentResized() •componentShown() •componentMoved() •componentHidden() ContainerListener •componentAdded() •componentRemoved() FocusListener •focusGained() •focusLost()
  • 15. Event Listener Interfaces ItemListener •itemStateChanged() KeyListener •keyTyped() •keyPressed() •keyReleased() MouseListener •mousePressed() •mouseClicked() •mouseEntered() •mouseExited() •mouseReleased() MouseMotionListener •mouseMoved() •mouseDragged() MouseWheelListener •mouseWheelMoved()
  • 16. Java MouseListener Interface  The Java MouseListener is notified whenever you change the state of mouse. It is notified against MouseEvent.  The MouseListener interface is found in java.awt.event package. It has five methods
  • 17. Methods of MouseListener interface  The signature of 5 methods found in MouseListener interface are given below:  public abstract void mouseClicked(MouseEvent e);  public abstract void mouseEntered(MouseEvent e);  public abstract void mouseExited(MouseEvent e);  public abstract void mousePressed(MouseEvent e);  public abstract void mouseReleased(MouseEvent e);
  • 20. Java KeyListener Interface  The Java KeyListener is notified whenever you change the state of key.  It is notified against KeyEvent. The KeyListener interface is found in java.awt.event package, and it has three methods
  • 21. Interface declaration  Following is the declaration for java.awt.event.KeyListener interface:  public interface KeyListener extends EventListener Sr. no. Method name Description 1. public abstract void keyPressed (KeyEvent e); It is invoked when a key has been pressed. 2. public abstract void keyReleased (KeyEvent e); It is invoked when a key has been released. 3. public abstract void keyTyped (KeyEvent e); It is invoked when a key has been typed