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

Introduction to Listview in Android
Introduction to Listview in AndroidIntroduction to Listview in Android
Introduction to Listview in Androidtechnoguff
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
Java annotations
Java annotationsJava annotations
Java annotationsFAROOK Samath
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls pptsoumyaharitha
 
android menus
android menusandroid menus
android menusDeepa Rani
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteTushar B Kute
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressionsLogan Chien
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in javayugandhar vadlamudi
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentationManeesha Caldera
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in JavaAyesha Kanwal
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And MultithreadingShraddha
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanagerArati Gadgil
 

What's hot (20)

Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Java: GUI
Java: GUIJava: GUI
Java: GUI
 
Introduction to Listview in Android
Introduction to Listview in AndroidIntroduction to Listview in Android
Introduction to Listview in Android
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Java annotations
Java annotationsJava annotations
Java annotations
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
 
Layout manager
Layout managerLayout manager
Layout manager
 
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
 
android menus
android menusandroid menus
android menus
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Java if else condition - powerpoint persentation
Java if else condition - powerpoint persentationJava if else condition - powerpoint persentation
Java if else condition - powerpoint persentation
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 

Similar to Java eventhandling

Java Event Handling
Java Event HandlingJava Event Handling
Java Event HandlingShraddha
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptsharanyak0721
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handlingteach4uin
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxGood657694
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03Ankit Dubey
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxudithaisur
 
Java gui event
Java gui eventJava gui event
Java gui eventSoftNutx
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVASrajan Shukla
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxusvirat1805
 
Mobile Application Development
Mobile Application DevelopmentMobile Application Development
Mobile Application DevelopmentMuhammad 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
 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Javaarnold 7490
 
event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.pptusama537223
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxTadeseBeyene
 
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 programmingSynapseindiappsdevelopment
 
File Handling
File HandlingFile Handling
File HandlingSohanur63
 

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
 
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
 
Event Handling in JAVA
Event Handling in JAVAEvent Handling in JAVA
Event Handling in JAVA
 
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)
 
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
 
File Handling
File HandlingFile Handling
File Handling
 
Jp notes
Jp notesJp notes
Jp notes
 

More from Arati Gadgil

Java adapter
Java adapterJava adapter
Java adapterArati Gadgil
 
Java networking
Java networkingJava networking
Java networkingArati Gadgil
 
Java package
Java packageJava package
Java packageArati Gadgil
 
Java interface
Java interfaceJava interface
Java interfaceArati Gadgil
 
Java inheritance
Java inheritanceJava inheritance
Java inheritanceArati Gadgil
 
Java exception
Java exception Java exception
Java exception Arati Gadgil
 
Java collection
Java collectionJava collection
Java collectionArati Gadgil
 

More from Arati Gadgil (14)

Java adapter
Java adapterJava adapter
Java adapter
 
Java swing
Java swingJava swing
Java swing
 
Java applet
Java appletJava applet
Java applet
 
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

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

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