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

PDF
Threads concept in java
PPTX
String, string builder, string buffer
PDF
OOP Assignment 03.pdf
PPT
SQLITE Android
PPTX
Event In JavaScript
PPTX
Java awt (abstract window toolkit)
PPTX
Constructor in java
PPT
Java layoutmanager
Threads concept in java
String, string builder, string buffer
OOP Assignment 03.pdf
SQLITE Android
Event In JavaScript
Java awt (abstract window toolkit)
Constructor in java
Java layoutmanager

What's hot (20)

PPT
Java And Multithreading
PPTX
Data Structures (CS8391)
PPTX
Multithreading in java
PDF
PDF
Servlet and servlet life cycle
PPTX
Array in c#
PDF
[Android] Widget Event Handling
PPTX
05 intent
ODP
Garbage collection
PPTX
Fundamentals of Python Programming
PPT
android activity
PDF
Polymorphism In Java
PPTX
Event Handling in java
PPTX
oops concept in java | object oriented programming in java
PPTX
Event Handling in JAVA
PPTX
Broadcast Receiver
PPTX
Lecture_7-Encapsulation in Java.pptx
PPTX
this keyword in Java.pptx
PPTX
PPTX
Chapter 07 inheritance
Java And Multithreading
Data Structures (CS8391)
Multithreading in java
Servlet and servlet life cycle
Array in c#
[Android] Widget Event Handling
05 intent
Garbage collection
Fundamentals of Python Programming
android activity
Polymorphism In Java
Event Handling in java
oops concept in java | object oriented programming in java
Event Handling in JAVA
Broadcast Receiver
Lecture_7-Encapsulation in Java.pptx
this keyword in Java.pptx
Chapter 07 inheritance
Ad

Similar to Java eventhandling (20)

PDF
Lecture 18
PPT
Java Event Handling
PPTX
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
PPTX
What is Event
PDF
Event Handling in Java as per university
PPTX
Event Handling in Java
PPT
Unit 5.133333333333333333333333333333333.ppt
PPT
engineeringdsgtnotesofunitfivesnists.ppt
PPTX
tL20 event handling
PDF
java-programming GUI- Event Handling.pdf
PPTX
event-handling.pptx
PPTX
Event handling
PPT
Chapter 8 event Handling.ppt m m m m m m
PDF
Ajp notes-chapter-03
PPTX
ITE 1122_ Event Handling.pptx
PPT
Java gui event
PPT
Swing_Introduction and working java.ppt
PDF
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
PPTX
event-handling.pptx
PPT
09events
Lecture 18
Java Event Handling
JAVA UNIT 5.pptx jejsjdkkdkdkjjndjfjfkfjfnfn
What is Event
Event Handling in Java as per university
Event Handling in Java
Unit 5.133333333333333333333333333333333.ppt
engineeringdsgtnotesofunitfivesnists.ppt
tL20 event handling
java-programming GUI- Event Handling.pdf
event-handling.pptx
Event handling
Chapter 8 event Handling.ppt m m m m m m
Ajp notes-chapter-03
ITE 1122_ Event Handling.pptx
Java gui event
Swing_Introduction and working java.ppt
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
event-handling.pptx
09events
Ad

More from Arati Gadgil (15)

PPT
Java adapter
PPT
Java swing
PPT
Java applet
PPT
Java awt
PPT
Java stream
PPT
Java thread
PPT
Java networking
PPT
Java jdbc
PPT
Java package
PPT
Java interface
PPT
Java inheritance
PPT
Java exception
PPT
Java collection
PPT
Java class
PPT
Java basic
Java adapter
Java swing
Java applet
Java awt
Java stream
Java thread
Java networking
Java jdbc
Java package
Java interface
Java inheritance
Java exception
Java collection
Java class
Java basic

Recently uploaded (20)

PPTX
Institutional Correction lecture only . . .
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Classroom Observation Tools for Teachers
PPTX
GDM (1) (1).pptx small presentation for students
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Lesson notes of climatology university.
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharma ospi slides which help in ospi learning
PDF
Computing-Curriculum for Schools in Ghana
Institutional Correction lecture only . . .
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Classroom Observation Tools for Teachers
GDM (1) (1).pptx small presentation for students
O7-L3 Supply Chain Operations - ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
2.FourierTransform-ShortQuestionswithAnswers.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPH.pptx obstetrics and gynecology in nursing
Anesthesia in Laparoscopic Surgery in India
O5-L3 Freight Transport Ops (International) V1.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Complications of Minimal Access Surgery at WLH
Renaissance Architecture: A Journey from Faith to Humanism
Module 4: Burden of Disease Tutorial Slides S2 2025
Lesson notes of climatology university.
VCE English Exam - Section C Student Revision Booklet
RMMM.pdf make it easy to upload and study
Pharma ospi slides which help in ospi learning
Computing-Curriculum for Schools in Ghana

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