SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
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 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

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Software Engineering
Introduction to Software EngineeringIntroduction to Software Engineering
Introduction to Software EngineeringMajane Padua
 
Transport layer security (tls)
Transport layer security (tls)Transport layer security (tls)
Transport layer security (tls)Kalpesh Kalekar
 
Virus and its CounterMeasures -- Pruthvi Monarch
Virus and its CounterMeasures                         -- Pruthvi Monarch Virus and its CounterMeasures                         -- Pruthvi Monarch
Virus and its CounterMeasures -- Pruthvi Monarch Pruthvi Monarch
 
An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...William Liang
 
Waterfall and spiral model
Waterfall and spiral modelWaterfall and spiral model
Waterfall and spiral modelyenohhoney
 
OOAD UNIT I UML DIAGRAMS
OOAD UNIT I UML DIAGRAMSOOAD UNIT I UML DIAGRAMS
OOAD UNIT I UML DIAGRAMSMikel Raj
 
unit 5 Architectural design
 unit 5 Architectural design unit 5 Architectural design
unit 5 Architectural designdevika g
 
Resource Allocation In Software Project Management
Resource Allocation In Software Project ManagementResource Allocation In Software Project Management
Resource Allocation In Software Project ManagementSyed Hassan Ali
 
Software development PROCESS
Software development PROCESSSoftware development PROCESS
Software development PROCESSIvano Malavolta
 
Interaction Modeling
Interaction ModelingInteraction Modeling
Interaction ModelingHemant Sharma
 
Multi Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesMulti Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesEthan Cha
 
05 architectural styles
05 architectural styles05 architectural styles
05 architectural stylesMajong DevJfu
 
Object oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptObject oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptKunal Kishor Nirala
 
requirment anlaysis , user requirements
requirment anlaysis , user requirementsrequirment anlaysis , user requirements
requirment anlaysis , user requirementscsk selva
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems SHATHAN
 
Distributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communicationDistributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communicationMNM Jain Engineering College
 

Was ist angesagt? (20)

Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Stream oriented communication
Stream oriented communicationStream oriented communication
Stream oriented communication
 
SE Unit 1
SE Unit 1SE Unit 1
SE Unit 1
 
Introduction to Software Engineering
Introduction to Software EngineeringIntroduction to Software Engineering
Introduction to Software Engineering
 
Object model
Object modelObject model
Object model
 
Transport layer security (tls)
Transport layer security (tls)Transport layer security (tls)
Transport layer security (tls)
 
Virus and its CounterMeasures -- Pruthvi Monarch
Virus and its CounterMeasures                         -- Pruthvi Monarch Virus and its CounterMeasures                         -- Pruthvi Monarch
Virus and its CounterMeasures -- Pruthvi Monarch
 
An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...An Introduction to the Android Framework -- a core architecture view from app...
An Introduction to the Android Framework -- a core architecture view from app...
 
Waterfall and spiral model
Waterfall and spiral modelWaterfall and spiral model
Waterfall and spiral model
 
OOAD UNIT I UML DIAGRAMS
OOAD UNIT I UML DIAGRAMSOOAD UNIT I UML DIAGRAMS
OOAD UNIT I UML DIAGRAMS
 
unit 5 Architectural design
 unit 5 Architectural design unit 5 Architectural design
unit 5 Architectural design
 
Resource Allocation In Software Project Management
Resource Allocation In Software Project ManagementResource Allocation In Software Project Management
Resource Allocation In Software Project Management
 
Software development PROCESS
Software development PROCESSSoftware development PROCESS
Software development PROCESS
 
Interaction Modeling
Interaction ModelingInteraction Modeling
Interaction Modeling
 
Multi Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And TypesMulti Touch And Gesture Event Interface And Types
Multi Touch And Gesture Event Interface And Types
 
05 architectural styles
05 architectural styles05 architectural styles
05 architectural styles
 
Object oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle pptObject oriented-systems-development-life-cycle ppt
Object oriented-systems-development-life-cycle ppt
 
requirment anlaysis , user requirements
requirment anlaysis , user requirementsrequirment anlaysis , user requirements
requirment anlaysis , user requirements
 
Synchronization in distributed systems
Synchronization in distributed systems Synchronization in distributed systems
Synchronization in distributed systems
 
Distributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communicationDistributed System-Multicast & Indirect communication
Distributed System-Multicast & Indirect communication
 

Ähnlich wie Java Programming :Event Handling(Types of Events)

Ähnlich wie Java Programming :Event Handling(Types of Events) (20)

Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
Event handling
Event handlingEvent handling
Event handling
 
Java gui event
Java gui eventJava gui event
Java gui event
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptx
 
Event handling
Event handlingEvent handling
Event handling
 
Event handling
Event handlingEvent handling
Event handling
 
What is Event
What is EventWhat is Event
What is Event
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
 
Event handling
Event handlingEvent handling
Event handling
 
File Handling
File HandlingFile Handling
File Handling
 

Mehr von simmis5

Software reuse is the use of existing artifacts to build new software compone...
Software reuse is the use of existing artifacts to build new software compone...Software reuse is the use of existing artifacts to build new software compone...
Software reuse is the use of existing artifacts to build new software compone...simmis5
 
Unified Modeling Language in Software Engineering
Unified Modeling Language in Software EngineeringUnified Modeling Language in Software Engineering
Unified Modeling Language in Software Engineeringsimmis5
 
JAVA SWING:Swing is a Java Foundation Classes [JFC] library and an extension ...
JAVA SWING:Swing is a Java Foundation Classes [JFC] library and an extension ...JAVA SWING:Swing is a Java Foundation Classes [JFC] library and an extension ...
JAVA SWING:Swing is a Java Foundation Classes [JFC] library and an extension ...simmis5
 
The Concept of Abstract Window Took Kit In Java
The Concept of Abstract Window Took Kit In JavaThe Concept of Abstract Window Took Kit In Java
The Concept of Abstract Window Took Kit In Javasimmis5
 
Software Engineering :Project Management
Software Engineering :Project ManagementSoftware Engineering :Project Management
Software Engineering :Project Managementsimmis5
 
The Concept Of Multithreading In Java Programming
The Concept Of Multithreading In Java ProgrammingThe Concept Of Multithreading In Java Programming
The Concept Of Multithreading In Java Programmingsimmis5
 
Conditional Statements & Loops
Conditional Statements & LoopsConditional Statements & Loops
Conditional Statements & Loopssimmis5
 
STRING HANDLING FUNCTIONS.pdf
STRING HANDLING FUNCTIONS.pdfSTRING HANDLING FUNCTIONS.pdf
STRING HANDLING FUNCTIONS.pdfsimmis5
 
Multiplexer.pdf
Multiplexer.pdfMultiplexer.pdf
Multiplexer.pdfsimmis5
 
Encoder_decoder_si.pdf
Encoder_decoder_si.pdfEncoder_decoder_si.pdf
Encoder_decoder_si.pdfsimmis5
 
c_algo_flowchart.pdf
c_algo_flowchart.pdfc_algo_flowchart.pdf
c_algo_flowchart.pdfsimmis5
 

Mehr von simmis5 (11)

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

Kürzlich hochgeladen

Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualBalamuruganV28
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfAshrafRagab14
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesRashidFaridChishti
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfragupathi90
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...Roi Lipman
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdfKamal Acharya
 
Circuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineeringCircuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineeringKanchhaTamang
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdfKamal Acharya
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2T.D. Shashikala
 
ChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdfChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdfqasastareekh
 
Lesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxLesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxmichaelprrior
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...ShivamTiwari995432
 
Theory for How to calculation capacitor bank
Theory for How to calculation capacitor bankTheory for How to calculation capacitor bank
Theory for How to calculation capacitor banktawat puangthong
 
Artificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian ReasoningArtificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian Reasoninghotman30312
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfEr.Sonali Nasikkar
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..MaherOthman7
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.MdManikurRahman
 
15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon15-Minute City: A Completely New Horizon
15-Minute City: A Completely New HorizonMorshed Ahmed Rahath
 
How to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdfHow to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdftawat puangthong
 

Kürzlich hochgeladen (20)

Final DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manualFinal DBMS Manual (2).pdf final lab manual
Final DBMS Manual (2).pdf final lab manual
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdf
 
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message QueuesLinux Systems Programming: Semaphores, Shared Memory, and Message Queues
Linux Systems Programming: Semaphores, Shared Memory, and Message Queues
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
 
Circuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineeringCircuit Breaker arc phenomenon.pdf engineering
Circuit Breaker arc phenomenon.pdf engineering
 
Online crime reporting system project.pdf
Online crime reporting system project.pdfOnline crime reporting system project.pdf
Online crime reporting system project.pdf
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
ChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdfChatGPT Prompt Engineering for project managers.pdf
ChatGPT Prompt Engineering for project managers.pdf
 
Lesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsxLesson no16 application of Induction Generator in Wind.ppsx
Lesson no16 application of Induction Generator in Wind.ppsx
 
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
Fabrication Of Automatic Star Delta Starter Using Relay And GSM Module By Utk...
 
Theory for How to calculation capacitor bank
Theory for How to calculation capacitor bankTheory for How to calculation capacitor bank
Theory for How to calculation capacitor bank
 
Artificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian ReasoningArtificial Intelligence Bayesian Reasoning
Artificial Intelligence Bayesian Reasoning
 
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdfInstruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
Instruct Nirmaana 24-Smart and Lean Construction Through Technology.pdf
 
Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..Maher Othman Interior Design Portfolio..
Maher Othman Interior Design Portfolio..
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon15-Minute City: A Completely New Horizon
15-Minute City: A Completely New Horizon
 
How to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdfHow to Design and spec harmonic filter.pdf
How to Design and spec harmonic filter.pdf
 

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);
  • 19.
  • 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