尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
JAVA
EventHandling
Prepared by
Miss. Arati A. Gadgil
EventHandling
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.
Foreground Events - Those events which require the direct
interaction of user
Background Events - Those events that require the interaction
of end user are known as background events
2
Source - The source is an object on which event occurs
Listener - It is also known as event handler. Listener is
responsible for generating response to an event.
Steps involved in event handling
•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. 3
4
Event Class Hierarchy
Each high level event class extends java.awt.AWTEvent.
java.lang.Object
| ---java.util.EventObject
| ---java.awt.AWTEvent
| ---java.awt.event.ActionEvent
| ---java.awt.event.ItemEvent
| ---java.awt.event.AdjustmentEvent
| ---java.awt.event.TextEvent
| ----java.awt.event.ComponentEvent
| ---java.awt.event.InputEvent |
| | ---java.awt.event.KeyEvent
| | ---java.awt.event.MouseEvent
| +---java.awt.event.FocusEvent
| +---java.awt.event.ContainerEvent
| +---java.awt.event.WindowEvent
5
Semantic and Low-Level Events in the AWT
A semantic event is one that expresses what the user is doing, such as
"clicking that button"; hence, an ActionEvent is a semantic event.
Low-level events are those events that make this possible. In the case of
a button click, this is a mouse down, a series of mouse moves, and a
mouse up (but only if the mouse up is inside the button area). Or it might
be a keystroke, which happens if the user selects the button with
the TAB key and then activates it with the space bar. Similarly, adjusting
a scrollbar is a semantic event, but dragging the mouse is a low-level
event.
Semantic event classes in the java.awt.event package:
ActionEvent (for a button click, a menu selection, selecting a list item,
or ENTER typed in a text field)
AdjustmentEvent (the user adjusted a scrollbar)
ItemEvent (the user made a selection from a set of checkbox or list
6
Five low-level event classes are commonly used:
•KeyEvent (a key was pressed or released)
•MouseEvent (the mouse button was pressed, released, moved, or
dragged)
•MouseWheelEvent (the mouse wheel was rotated)
•FocusEvent (a component got focus, or lost focus). See page 321 for
more information about the focus concept.
•WindowEvent (the window state changed)
AWT ActionListener Interface
Method
void actionPerformed(ActionEvent e)
Invoked when an action occurs.
The Event listener represent the interfaces
responsible to handle events.
7
AWT MouseListener Interface
Methods
•void mouseClicked(MouseEvent e)
Invoked when the mouse button has been clicked (pressed and
released) on a component.
•void mouseEntered(MouseEvent e)
Invoked when the mouse enters a component
•void mouseExited(MouseEvent e)
Invoked when the mouse exits a component.
•void mousePressed(MouseEvent e)
Invoked when a mouse button has been pressed on a component.
•void mouseReleased(MouseEvent e)
Invoked when a mouse button has been released on a
component.
.
8
AWT WindowListener Interface
Methods
void windowActivated(WindowEvent e)
Invoked when the Window is set to be the active Window
void windowClosed(WindowEvent e)
Invoked when a window has been closed as the result of calling dispose
on the window.
void windowClosing(WindowEvent e)
Invoked when the user attempts to close the window from the window's
system menu.
void windowDeactivated(WindowEvent e)
Invoked when a Window is no longer the active Window
9
void windowDeiconified(WindowEvent e)
Invoked when a window is changed from a
minimized to a normal state
void windowIconified(WindowEvent e)
Invoked when a window is changed from a
normal to a minimized state.
void windowOpened(WindowEvent e)
Invoked the first time a window is made visible.
10
import java.awt.*;
import java.awt.event.*;
class frmw extends Frame implements WindowListener
{
frmw()
{
super("window Listener");
addWindowListener(this);
setSize(300,300);
setVisible(true);
}
public void windowActivated(WindowEvent e)
{
System.out.println("Activated");
}
11
public void windowDeactivated(WindowEvent e)
{
System.out.println("Deactivated");
}
public void windowIconified(WindowEvent e)
{
System.out.println("Iconified");
}
public void windowDeiconified(WindowEvent e)
{
System.out.println("Deiconified");
}
public void windowOpened(WindowEvent e)
{
System.out.println("opened");
} 12
public void windowClosed(WindowEvent e)
{
System.out.println("closed");
}
public void windowClosing(WindowEvent e)
{
System.out.println("closing");
}
public static void main(String []a)
{
frmw k=new frmw();
}
}
13
AWT MouseMotionListener Interface
Methods
void mouseDragged(MouseEvent e)
Invoked when a mouse button is pressed on a component and then
dragged
void mouseMoved(MouseEvent e)
Invoked when the mouse cursor has been moved onto a component
but no buttons have been pushed
14
AWT FocusListener Interface
Methods
void focusGained(FocusEvent e)
Invoked when a component gains the keyboard focus
void focusLost(FocusEvent e)
Invoked when a component loses the keyboard focus
15
Thank You
16

More Related Content

What's hot

Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Edureka!
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
Abhishek Sur
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
TheCreativedev Blog
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
soumyaharitha
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
rishisingh190
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
Nikolaus Graf
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
Cakra Danu Sedayu
 
Reactjs
Reactjs Reactjs
Reactjs
Neha Sharma
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
Varun Raj
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
L&T Technology Services Limited
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
Hùng Nguyễn Huy
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
Vatsal N Shah
 
React workshop
React workshopReact workshop
React workshop
Imran Sayed
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
Ayesha Kanwal
 
Java Methods
Java MethodsJava Methods
Java Methods
OXUS 20
 
Applets
AppletsApplets
java 8 new features
java 8 new features java 8 new features
java 8 new features
Rohit Verma
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
MicroPyramid .
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
Srajan Shukla
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
All Things Open
 

What's hot (20)

Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
ASP.NET Page Life Cycle
ASP.NET Page Life CycleASP.NET Page Life Cycle
ASP.NET Page Life Cycle
 
Node.js Express Framework
Node.js Express FrameworkNode.js Express Framework
Node.js Express Framework
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
 
Exception Handling in VB.Net
Exception Handling in VB.NetException Handling in VB.Net
Exception Handling in VB.Net
 
React + Redux Introduction
React + Redux IntroductionReact + Redux Introduction
React + Redux Introduction
 
Build RESTful API Using Express JS
Build RESTful API Using Express JSBuild RESTful API Using Express JS
Build RESTful API Using Express JS
 
Reactjs
Reactjs Reactjs
Reactjs
 
Introduction to React JS for beginners
Introduction to React JS for beginners Introduction to React JS for beginners
Introduction to React JS for beginners
 
JavaScript Promises
JavaScript PromisesJavaScript Promises
JavaScript Promises
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
Nodejs vatsal shah
Nodejs vatsal shahNodejs vatsal shah
Nodejs vatsal shah
 
React workshop
React workshopReact workshop
React workshop
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
Java Methods
Java MethodsJava Methods
Java Methods
 
Applets
AppletsApplets
Applets
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
An Introduction to ReactJS
An Introduction to ReactJSAn Introduction to ReactJS
An Introduction to ReactJS
 

Similar to Java eventhandling

Lecture 18
Lecture 18Lecture 18
Lecture 18
Debasish Pratihari
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
Shraddha
 
What is Event
What is EventWhat is Event
What is Event
Asmita Prasad
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
teach4uin
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
Good657694
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
Ankit Dubey
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
udithaisur
 
Java gui event
Java gui eventJava gui event
Java gui event
SoftNutx
 
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
Jyothishmathi Institute of Technology and Science Karimnagar
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
usvirat1805
 
09events
09events09events
09events
Waheed Warraich
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application Development
Muhammad Sajid
 
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
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
arnold 7490
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
usama537223
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindiappsdevelopment
 

Similar to Java eventhandling (20)

Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
 
What is Event
What is EventWhat is Event
What is Event
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Event handling
Event handlingEvent handling
Event handling
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Java gui event
Java gui eventJava gui event
Java gui event
 
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
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
09events
09events09events
09events
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application Development
 
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 AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
 

More from Arati Gadgil

Java adapter
Java adapterJava adapter
Java adapter
Arati Gadgil
 
Java swing
Java swingJava swing
Java swing
Arati Gadgil
 
Java applet
Java appletJava applet
Java applet
Arati Gadgil
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
Arati Gadgil
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
Java stream
Java streamJava stream
Java stream
Arati Gadgil
 
Java thread
Java threadJava thread
Java thread
Arati Gadgil
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
Arati Gadgil
 
Java package
Java packageJava package
Java package
Arati Gadgil
 
Java interface
Java interfaceJava interface
Java interface
Arati Gadgil
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Java exception
Java exception Java exception
Java exception
Arati Gadgil
 
Java collection
Java collectionJava collection
Java collection
Arati Gadgil
 
Java class
Java classJava class
Java class
Arati Gadgil
 
Java basic
Java basicJava basic
Java basic
Arati Gadgil
 

More from Arati Gadgil (16)

Java adapter
Java adapterJava adapter
Java adapter
 
Java swing
Java swingJava swing
Java swing
 
Java applet
Java appletJava applet
Java applet
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
Java awt
Java awtJava awt
Java awt
 
Java stream
Java streamJava stream
Java stream
 
Java thread
Java threadJava thread
Java thread
 
Java networking
Java networkingJava networking
Java networking
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
Java package
Java packageJava package
Java package
 
Java interface
Java interfaceJava interface
Java interface
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Java exception
Java exception Java exception
Java exception
 
Java collection
Java collectionJava collection
Java collection
 
Java class
Java classJava class
Java class
 
Java basic
Java basicJava basic
Java basic
 

Recently uploaded

bryophytes.pptx bsc botany honours second semester
bryophytes.pptx bsc botany honours  second semesterbryophytes.pptx bsc botany honours  second semester
bryophytes.pptx bsc botany honours second semester
Sarojini38
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
Nguyen Thanh Tu Collection
 
Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024
Friends of African Village Libraries
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
MattVassar1
 
Talking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual AidsTalking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual Aids
MattVassar1
 
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
Kalna College
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
Erasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES CroatiaErasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES Croatia
whatchangedhowreflec
 
managing Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptxmanaging Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptx
nabaegha
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
 
The Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teachingThe Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teaching
Derek Wenmoth
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
Kalna College
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
heathfieldcps1
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
Kalna College
 
The Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptxThe Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptx
PriyaKumari928991
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
RuchiRathor2
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
Kalna College
 
Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
Ben Aldrich
 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
biruktesfaye27
 

Recently uploaded (20)

bryophytes.pptx bsc botany honours second semester
bryophytes.pptx bsc botany honours  second semesterbryophytes.pptx bsc botany honours  second semester
bryophytes.pptx bsc botany honours second semester
 
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
BỘ BÀI TẬP TEST THEO UNIT - FORM 2025 - TIẾNG ANH 12 GLOBAL SUCCESS - KÌ 1 (B...
 
Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024Library news letter Kitengesa Uganda June 2024
Library news letter Kitengesa Uganda June 2024
 
Non-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech ProfessionalsNon-Verbal Communication for Tech Professionals
Non-Verbal Communication for Tech Professionals
 
Talking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual AidsTalking Tech through Compelling Visual Aids
Talking Tech through Compelling Visual Aids
 
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...220711130095 Tanu Pandey message currency, communication speed & control EPC ...
220711130095 Tanu Pandey message currency, communication speed & control EPC ...
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
Erasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES CroatiaErasmus + DISSEMINATION ACTIVITIES Croatia
Erasmus + DISSEMINATION ACTIVITIES Croatia
 
managing Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptxmanaging Behaviour in early childhood education.pptx
managing Behaviour in early childhood education.pptx
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
 
The Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teachingThe Science of Learning: implications for modern teaching
The Science of Learning: implications for modern teaching
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
 
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx78 Microsoft-Publisher - Sirin Sultana Bora.pptx
78 Microsoft-Publisher - Sirin Sultana Bora.pptx
 
The Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptxThe Rise of the Digital Telecommunication Marketplace.pptx
The Rise of the Digital Telecommunication Marketplace.pptx
 
8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity8+8+8 Rule Of Time Management For Better Productivity
8+8+8 Rule Of Time Management For Better Productivity
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
 
Interprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdfInterprofessional Education Platform Introduction.pdf
Interprofessional Education Platform Introduction.pdf
 
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
Ethiopia and Eritrea Eritrea's journey has been marked by resilience and dete...
 

Java eventhandling

  • 2. EventHandling 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. Foreground Events - Those events which require the direct interaction of user Background Events - Those events that require the interaction of end user are known as background events 2
  • 3. Source - The source is an object on which event occurs Listener - It is also known as event handler. Listener is responsible for generating response to an event. Steps involved in event handling •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. 3
  • 4. 4 Event Class Hierarchy Each high level event class extends java.awt.AWTEvent. java.lang.Object | ---java.util.EventObject | ---java.awt.AWTEvent | ---java.awt.event.ActionEvent | ---java.awt.event.ItemEvent | ---java.awt.event.AdjustmentEvent | ---java.awt.event.TextEvent | ----java.awt.event.ComponentEvent | ---java.awt.event.InputEvent | | | ---java.awt.event.KeyEvent | | ---java.awt.event.MouseEvent | +---java.awt.event.FocusEvent | +---java.awt.event.ContainerEvent | +---java.awt.event.WindowEvent
  • 5. 5 Semantic and Low-Level Events in the AWT A semantic event is one that expresses what the user is doing, such as "clicking that button"; hence, an ActionEvent is a semantic event. Low-level events are those events that make this possible. In the case of a button click, this is a mouse down, a series of mouse moves, and a mouse up (but only if the mouse up is inside the button area). Or it might be a keystroke, which happens if the user selects the button with the TAB key and then activates it with the space bar. Similarly, adjusting a scrollbar is a semantic event, but dragging the mouse is a low-level event. Semantic event classes in the java.awt.event package: ActionEvent (for a button click, a menu selection, selecting a list item, or ENTER typed in a text field) AdjustmentEvent (the user adjusted a scrollbar) ItemEvent (the user made a selection from a set of checkbox or list
  • 6. 6 Five low-level event classes are commonly used: •KeyEvent (a key was pressed or released) •MouseEvent (the mouse button was pressed, released, moved, or dragged) •MouseWheelEvent (the mouse wheel was rotated) •FocusEvent (a component got focus, or lost focus). See page 321 for more information about the focus concept. •WindowEvent (the window state changed)
  • 7. AWT ActionListener Interface Method void actionPerformed(ActionEvent e) Invoked when an action occurs. The Event listener represent the interfaces responsible to handle events. 7
  • 8. AWT MouseListener Interface Methods •void mouseClicked(MouseEvent e) Invoked when the mouse button has been clicked (pressed and released) on a component. •void mouseEntered(MouseEvent e) Invoked when the mouse enters a component •void mouseExited(MouseEvent e) Invoked when the mouse exits a component. •void mousePressed(MouseEvent e) Invoked when a mouse button has been pressed on a component. •void mouseReleased(MouseEvent e) Invoked when a mouse button has been released on a component. . 8
  • 9. AWT WindowListener Interface Methods void windowActivated(WindowEvent e) Invoked when the Window is set to be the active Window void windowClosed(WindowEvent e) Invoked when a window has been closed as the result of calling dispose on the window. void windowClosing(WindowEvent e) Invoked when the user attempts to close the window from the window's system menu. void windowDeactivated(WindowEvent e) Invoked when a Window is no longer the active Window 9
  • 10. void windowDeiconified(WindowEvent e) Invoked when a window is changed from a minimized to a normal state void windowIconified(WindowEvent e) Invoked when a window is changed from a normal to a minimized state. void windowOpened(WindowEvent e) Invoked the first time a window is made visible. 10
  • 11. import java.awt.*; import java.awt.event.*; class frmw extends Frame implements WindowListener { frmw() { super("window Listener"); addWindowListener(this); setSize(300,300); setVisible(true); } public void windowActivated(WindowEvent e) { System.out.println("Activated"); } 11
  • 12. public void windowDeactivated(WindowEvent e) { System.out.println("Deactivated"); } public void windowIconified(WindowEvent e) { System.out.println("Iconified"); } public void windowDeiconified(WindowEvent e) { System.out.println("Deiconified"); } public void windowOpened(WindowEvent e) { System.out.println("opened"); } 12
  • 13. public void windowClosed(WindowEvent e) { System.out.println("closed"); } public void windowClosing(WindowEvent e) { System.out.println("closing"); } public static void main(String []a) { frmw k=new frmw(); } } 13
  • 14. AWT MouseMotionListener Interface Methods void mouseDragged(MouseEvent e) Invoked when a mouse button is pressed on a component and then dragged void mouseMoved(MouseEvent e) Invoked when the mouse cursor has been moved onto a component but no buttons have been pushed 14
  • 15. AWT FocusListener Interface Methods void focusGained(FocusEvent e) Invoked when a component gains the keyboard focus void focusLost(FocusEvent e) Invoked when a component loses the keyboard focus 15
  翻译: