SlideShare ist ein Scribd-Unternehmen logo
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?

Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
Md.Al-imran Roton
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
Michelle Anne Meralpis
 
Software Devlopment Life Cycle
Software Devlopment Life CycleSoftware Devlopment Life Cycle
Software Devlopment Life Cycle
Vivek Gupta
 
Software development process basic
Software development process basicSoftware development process basic
Software development process basic
Anurag Tomar
 
Java package
Java packageJava package
Java package
CS_GDRCST
 
Event handling
Event handlingEvent handling
Data flow oriented modeling
Data flow oriented modelingData flow oriented modeling
Data flow oriented modeling
KavithaGowri
 
Static analysis
Static analysisStatic analysis
Static analysis
GowriLatha1
 
Android Components
Android ComponentsAndroid Components
Android Components
Aatul Palandurkar
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
Krazy Koder
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
Hamid Ghorbani
 
.Net Assemblies
.Net Assemblies.Net Assemblies
.Net Assemblies
Muhammad Kamran Rafi
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERING
Saqib Raza
 
Managment spectrum
Managment spectrumManagment spectrum
Java swing
Java swingJava swing
Java swing
ssuser3a47cb
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
parag
 

Was ist angesagt? (20)

Software Development Life Cycle
Software Development Life CycleSoftware Development Life Cycle
Software Development Life Cycle
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Software Devlopment Life Cycle
Software Devlopment Life CycleSoftware Devlopment Life Cycle
Software Devlopment Life Cycle
 
Software development process basic
Software development process basicSoftware development process basic
Software development process basic
 
Java package
Java packageJava package
Java package
 
Event handling
Event handlingEvent handling
Event handling
 
Data flow oriented modeling
Data flow oriented modelingData flow oriented modeling
Data flow oriented modeling
 
Static analysis
Static analysisStatic analysis
Static analysis
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
 
Java I/o streams
Java I/o streamsJava I/o streams
Java I/o streams
 
.Net Assemblies
.Net Assemblies.Net Assemblies
.Net Assemblies
 
REQUIREMENT ENGINEERING
REQUIREMENT ENGINEERINGREQUIREMENT ENGINEERING
REQUIREMENT ENGINEERING
 
Managment spectrum
Managment spectrumManagment spectrum
Managment spectrum
 
Java swing
Java swingJava swing
Java swing
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 

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

Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
arnold 7490
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
Ayesha Kanwal
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
udithaisur
 
Advance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handlingAdvance Java Programming(CM5I) Event handling
Advance Java Programming(CM5I) Event handling
Payal Dungarwal
 
Event handling in Java(part 1)
Event handling in Java(part 1)Event handling in Java(part 1)
Event handling in Java(part 1)
RAJITHARAMACHANDRAN1
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
Ankit Dubey
 
Java gui event
Java gui eventJava gui event
Java gui event
SoftNutx
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptx
Tanzila Kehkashan
 
Event handling
Event handlingEvent handling
Event handling
Ravi_Kant_Sahu
 
Event handling
Event handlingEvent handling
Event handling
Ravi Kant Sahu
 
What is Event
What is EventWhat is Event
What is Event
Asmita Prasad
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
usvirat1805
 
Event+driven+programming key+features
Event+driven+programming key+featuresEvent+driven+programming key+features
Event+driven+programming key+features
Faisal Aziz
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
Srajan Shukla
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
Amol Gaikwad
 
PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
Michael Heron
 
File Handling
File HandlingFile Handling
File Handling
Sohanur63
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
Debasish Pratihari
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
SivaSankari36
 

Ä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)
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
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
 
File Handling
File HandlingFile Handling
File Handling
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
 

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 Engineering
simmis5
 
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 Java
simmis5
 
Software Engineering :Project Management
Software Engineering :Project ManagementSoftware Engineering :Project Management
Software Engineering :Project Management
simmis5
 
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
simmis5
 
Conditional Statements & Loops
Conditional Statements & LoopsConditional Statements & Loops
Conditional Statements & Loops
simmis5
 
STRING HANDLING FUNCTIONS.pdf
STRING HANDLING FUNCTIONS.pdfSTRING HANDLING FUNCTIONS.pdf
STRING HANDLING FUNCTIONS.pdf
simmis5
 
Multiplexer.pdf
Multiplexer.pdfMultiplexer.pdf
Multiplexer.pdf
simmis5
 
Encoder_decoder_si.pdf
Encoder_decoder_si.pdfEncoder_decoder_si.pdf
Encoder_decoder_si.pdf
simmis5
 
c_algo_flowchart.pdf
c_algo_flowchart.pdfc_algo_flowchart.pdf
c_algo_flowchart.pdf
simmis5
 

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

john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
Las Vegas Warehouse
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
TaghreedAltamimi
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
shahdabdulbaset
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
Yasser Mahgoub
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 

Kürzlich hochgeladen (20)

john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have oneISPM 15 Heat Treated Wood Stamps and why your shipping must have one
ISPM 15 Heat Treated Wood Stamps and why your shipping must have one
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Software Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.pptSoftware Quality Assurance-se412-v11.ppt
Software Quality Assurance-se412-v11.ppt
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Hematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood CountHematology Analyzer Machine - Complete Blood Count
Hematology Analyzer Machine - Complete Blood Count
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
2008 BUILDING CONSTRUCTION Illustrated - Ching Chapter 02 The Building.pdf
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.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