SlideShare a Scribd company logo
1 of 67
Download to read offline
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
1
Prepared By: Asst. Prof. Sejal Jadav
Unit-5
CS ā€“ 19 : Programming with Java
UNIT ā€“ 5
GUI using SWING, Event Handling
B.C.A & B.SC.(IT) ā€“ 4
Prepared By: Asst. Prof. Sejal Jadav
Event Handling
Unit-5(Part-2)
Prepared By: Asst. Prof. Sejal Jadav
Event Classes
and
Listener Interfaces
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Event Classes Listener Interfaces
ActionEvent ActionListener
ItemEvent ItemListener
FocusEvent FocusListener
MouseEvent MouseListener and MouseMotionListener
MouseWheelEvent MouseWheelListener
TextEvent TextListener
KeyEvent KeyListener
Prepared By: Asst. Prof. Sejal Jadav
Q-8 Explain FocusEvent Class.
ā€¢ A FocusEvent is generated when a component gains or loses input
focus.
FOCUS_GAINED
ā€¢ It is set when the component gains the input focus.
FOCUS_LOST
ā€¢ It is set when the component loses the input focus.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ FocusEvent is a subclass of ComponentEvent and has these
constructors:
ā€¢ FocusEvent(Component src, int type)
ā€¢ FocusEvent(Component src, int type, boolean temporaryFlag)
ā€¢ Here, src is a reference to the component that generated this event. The type
of the event is specified by type. The argument temporaryFlag is set to true if
the focus event is temporary. Otherwise, it is set to false.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ (A temporary focus event occurs as a result of another user interface
operation.
ā€¢ For example, assume that the focus is in a text field. If the user moves
the mouse to adjust a scroll bar, the focus is temporarily lost.)
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ The isTemporary( ) method indicates if this focus change is temporary.
Its form is shown here:
boolean isTemporary( )
ā€¢ The method returns true if the change is temporary. Otherwise, it
returns false.
Prepared By: Asst. Prof. Sejal Jadav
Q: 15 The FocusListener Interface:
ā€¢ This interface defines two methods which are called when a component
gets or loses the focus.
void focusGained(FocusEvent fe)
void focusLost(FocusEvent fe)
ā€¢ Example: AwtListenerDemo.java
Prepared By: Asst. Prof. Sejal Jadav
Q: Java Adapter Classes
ā€¢ Java adapter classes provide the default implementation of listener
interfaces.
ā€¢ If you inherit the adapter class, you will not be forced to provide the
implementation of all the methods of listener interfaces.
ā€¢ So it saves code.
Prepared By: Asst. Prof. Sejal Jadav
Swing Focus Adapter
ā€¢ 1. FocusAdapter class is an abstract adapter class in Java Swing.
ā€¢ 2. FocusAdapter class is for receiving keyboard focus events.
ā€¢ 3. Methods specified in FocusAdapter class are empty.
ā€¢ 4. FocusAdapter class exists as convenience(suitable) for creating
listener objects
Prepared By: Asst. Prof. Sejal Jadav
Class declaration
ā€¢ Below is the declaration for java.awt.event.FocusAdapter class ā€“
public abstract class FocusAdapter extends Object
implements FocusListener
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Class constructors: FocusAdapter()
Class methods:
No. Method Return Type Parameter Invoked when
1 focusGained() void FocusEvent
component gains the
keyboard focus
2 focusLost() void FocusEvent
component loses the
keyboard focus
Prepared By: Asst. Prof. Sejal Jadav
Methods inherited:
ā€¢ This class inherits methods from the following classes:
java.lang.Object
ļ¶Swing Focus Adapter Example: AdapterExample.java
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Event Classes Listener Interfaces
ActionEvent ActionListener
ItemEvent ItemListener
FocusEvent FocusListener
MouseEvent MouseListener and MouseMotionListener
MouseWheelEvent MouseWheelListener
TextEvent TextListener
KeyEvent KeyListener
Prepared By: Asst. Prof. Sejal Jadav
Q-10 Explain KeyEvent Class.
ā€¢ A KeyEvent is generated when keyboard input occurs. There are three
types of key events, which are identified by these integer constants:
KEY_PRESSED
ā€¢ It is set when a key is pressed in the keyboard.
KEY_RELEASED
ā€¢ It is set when a key is pressed in the keyboard.
Prepared By: Asst. Prof. Sejal Jadav
KEY_TYPED
ā€¢ It is set when a printable key is pressed. The key such as ALT, CTRL,
SHIFT, etc are not printable character.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ There are many other integer constants that are defined by KeyEvent.
For example, VK_0 through VK_9 and VK_A through VK_Z define the
ASCII equivalents of the numbers and letters.
ā€¢ Here are some others:
Prepared By: Asst. Prof. Sejal Jadav
Here are some others:
ā€¢ The VK constants specify virtual key codes and are independent of any
modifiers, such as control, shift, or alt.
VK_ENTER VK_ESCAPE VK_CANCEL
VK_UP VK_DOWN VK_LEFT
VK_RIGHT VK_PAGE_DOWN
VK_PAGE_UP VK_SHIFT VK_ALT
VK_CONTROL
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ KeyEvent is a subclass of InputEvent. Here are two of its constructors:
KeyEvent(Component src, int type, long when, int modifiers, int
code)
KeyEvent(Component src, int type, long when, int modifiers, int
code, char ch)
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ Here, src is a reference to the component that generated the event. The
type of the event is specified by type.
ā€¢ The system time at which the key was pressed is passed in when.
ā€¢ The modifiers argument indicates which modifiers were pressed when
this key event occurred.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ The virtual key code, such as VK_UP, VK_A, and so forth, is passed in
code.
ā€¢ The character equivalent (if one exists) is passed in ch.
ā€¢ If no valid character exists, then ch contains CHAR_UNDEFINED.
ā€¢ For KEY_TYPED events, code will contain VK_UNDEFINED.
Prepared By: Asst. Prof. Sejal Jadav
The most commonly used methods of KeyEvent class are:
char getKeyChar( )
ā€¢ It returns the character that was pressed entered.
getKeyCode( )
ā€¢ It returns the code of the key pressed.
Prepared By: Asst. Prof. Sejal Jadav
Q: 15) The KeyListener Interface:
ā€¢ This interface defines three methods.
void keyPressed(KeyEvent ke)
ā€¢ This method is called when a keyboard key is pressed.
void keyReleased(KeyEvent ke)
ā€¢ This method is called when a keyboard key is released.
void keyTyped(KeyEvent ke)
ā€¢ This method is called when a printable character key is pressed.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ Example: KeyEvents.java
Prepared By: Asst. Prof. Sejal Jadav
Java KeyAdapter Example [page- 24]
ā€¢ The class KeyAdapter is an abstract (adapter) class for receiving
keyboard events.
ā€¢ All methods of this class are empty. This class is convenience class for
creating listener objects.
Prepared By: Asst. Prof. Sejal Jadav
ļ± Class declaration
ā€¢ Following is the declaration for java.awt.event.KeyAdapter class:
public abstract class KeyAdapter
extendsObject
implements KeyListener
ā€¢ Example: KeyAdapterExample.java
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Event Classes Listener Interfaces
ActionEvent ActionListener
ItemEvent ItemListener
FocusEvent FocusListener
MouseEvent MouseListener and MouseMotionListener
MouseWheelEvent MouseWheelListener
TextEvent TextListener
KeyEvent KeyListener
Prepared By: Asst. Prof. Sejal Jadav
Q-11 Explain MouseEvent Class.
ā€¢ There are seven types of mouse events.
ā€¢ The MouseEvent class defines the following integer constants that can be
used to identify them:
MOUSE_CLICKED
ā€¢ The user clicked the mouse.
MOUSE_DRAGGED
ā€¢ The user dragged the mouse.
Prepared By: Asst. Prof. Sejal Jadav
MOUSE_ENTERED
ā€¢ The mouse entered a component.
MOUSE_EXITED
ā€¢ The mouse exited from a
component.
MOUSE_MOVED
ā€¢ The mouse moved.
MOUSE_PRESSED
ā€¢ The mouse was pressed.
MOUSE_RELEASED
ā€¢ The mouse was released.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ MouseEvent is a subclass of InputEvent.
Here is one of its constructors.
MouseEvent(Component src, int type, long when, int modifiers, int x, int
y, int clickCount, boolean opensPopup)
Prepared By: Asst. Prof. Sejal Jadav
MouseEvent(Component src, int type, long when, int
modifiers, int x, int y, int clickCount, boolean opensPopup)
ā€¢ Here, src is a reference to the component that generated the event.
ā€¢ The type is the type of the event and time specifies the system time at which the event was
generated.
ā€¢ The modifiers parameter specifies any modifier keys that were pressed during the event.
ā€¢ The x and y are the coordinates of the mouse location.
ā€¢ The clickCount stores the number of mouse click.
ā€¢ When opensPopup is true, it specifies that any popup menu was opened after the mouse
event.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ The commonly used methods of MouseEvent are:
int getX( )
ā€¢ It returns the x coordinate of the mouse cursor.
int getY( )
ā€¢ It returns the y coordinate of the mouse cursor.
Prepared By: Asst. Prof. Sejal Jadav
void translatePoint(int x, int y)
ā€¢ It translate the mouse pointer to specified x and y location.
int getClickCount( )
ā€¢ It returns the number of mouse pointer clicked. For example 2 for double
click.
boolean isPopupTrigger( )
ā€¢ It returns the true if any popup was opened after the mouse event.
Prepared By: Asst. Prof. Sejal Jadav
Q: 15 ) The MouseListener Interface:
ā€¢ This interface defines five methods which are called when a mouse event is
generated These methods are:
void mouseClicked(MouseEvent me)
ā€¢ This method is called when the mouse button is clicked.
void mouseEntered(MouseEvent me)
ā€¢ This method is called when the mouse button is entered into a component.
Prepared By: Asst. Prof. Sejal Jadav
void mouseExited(MouseEvent me)
ā€¢ This method is called when the mouse button is exited from a component.
void mousePressed(MouseEvent me)
ā€¢ This method is called when the mouse button is pressed.
void mouseReleased(MouseEvent me)
ā€¢ This method is called when the mouse button is released.
Prepared By: Asst. Prof. Sejal Jadav
Q: 15) The MouseMotionListener Interface:
ā€¢ This interface defines two methods.
void mouseDragged(MouseEvent me)
ā€¢ This method is called the mouse is dragged.
void mouseMoved(MouseEvent me)
ā€¢ This method is called when mouse pointer is moved.
Prepared By: Asst. Prof. Sejal Jadav
Q-15) The MouseWheelListener Interface:
ā€¢ It has one method:
void mouseWheelMoved(MouseWheelEvent mwe)
ā€¢ This method is called when the wheel of the mouse is moved.
ā€¢ Example: Q-16 Mouse Handling Program:
ā€¢ MouseEvents.java
Prepared By: Asst. Prof. Sejal Jadav
Q: Java MouseAdapter Example [page: 23]
ā€¢ The class MouseAdapter is an abstract (adapter) class for receiving
mouse events.
ā€¢ All methods of this class are empty. This class is convenience class for
creating listener objects.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ Class declaration:
ā€¢ Following is the declaration for java.awt.event.MouseAdapter class:
Public abstract class MouseAdapter extends Object
implements
MouseListener,MouseWheelListener,MouseMotionListener
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ Example: MouseAdapterExample.java
Prepared By: Asst. Prof. Sejal Jadav
Q: Java MouseMotionAdapter Example [page:23]
ā€¢ The class MouseMotionAdapter is an abstract (adapter) class for
receiving mouse motion events.
ā€¢ All methods of this class are empty. This class is convenience class for
creating listener objects.
Prepared By: Asst. Prof. Sejal Jadav
ļ¶ Class Declaration
ā€¢ Following is the declaration for java.awt.event.MouseMotionAdapter
class āˆ’
public abstract class MouseMotionAdapter
extends Object
implements MouseMotionListener
ā€¢ Example:MouseMotionAdapterExample.java
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Event Classes Listener Interfaces
ActionEvent ActionListener
ItemEvent ItemListener
FocusEvent FocusListener
MouseEvent MouseListener and MouseMotionListener
MouseWheelEvent MouseWheelListener
TextEvent TextListener
KeyEvent KeyListener
Prepared By: Asst. Prof. Sejal Jadav
Q-12 Explain TextEvent Class.
ā€¢ The TextEvent is generated when user inputs some text into a text field or a
text area. It has one integer constant.
TEXT_VALUE_CHANGED
ā€¢ It is set when the text in a text field or a text area changed.
ā€¢ Its constructor is: TextEvent(Object source,int type)
ā€¢ Here source is the object that generated this event.
ā€¢ The type is the type event which can be TEXT_VALUE_CHANGED.
Prepared By: Asst. Prof. Sejal Jadav
Q:15) The TextListener Interface:
ā€¢ This interface ha one method:
void textChanged(TextEvent te)
ā€¢ It is called when the text of a text area or text field is changed.
ā€¢ Example: JavaExampleTextEvent.java
Prepared By: Asst. Prof. Sejal Jadav
Q-13 Explain WindowEvent Class.
ā€¢ The WindowEvent class handles the events related to a window and it is
a subclass of ComponentEvent class.
ā€¢ There are ten types of window events constant:
WINDOW_ACTIVATED
ā€¢ The window was activated.
Prepared By: Asst. Prof. Sejal Jadav
WINDOW_DEACTIVATED
ā€¢ The window was deactivated.
WINDOW_CLOSED
ā€¢ The window has been closed.
WINDOW_CLOSING
ā€¢ The user requested that the window be closed.
Prepared By: Asst. Prof. Sejal Jadav
WINDOW_OPENED
ā€¢ The window was opened.
WINDOW_GAINED_FOCUS
ā€¢ The window gained input focus.
WINDOW_LOST_FOCUS
ā€¢ The window lost input focus.
Prepared By: Asst. Prof. Sejal Jadav
WINDOW_ICONIFIED
ā€¢ The window was iconified. Ex it is minimized
WINDOW_DEICONIFIED
ā€¢ The window was deiconified. Ex it is restored
WINDOW_STATE_CHANGED
ā€¢ It is set when the state of the window is changed.
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ The constructors of WindowEvent are:
ā€¢ WindowEvent(Window source, int type)
ā€¢ WindowEvent(Window source, int type, Window other)
ā€¢ WindowEvent(Window source, int type, int oldState, int newState)
ā€¢ WindowEvent(Window source, int type, Window other, int oldState, int
newState)
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ Here, source is the window object that generated the window event.
ā€¢ The type specifies the type of event such as WINDOW_CLOSING etc.
ā€¢ The other specifies the opposite window when a focus event occurs.
ā€¢ The oldState is the previous state of the event.
ā€¢ The newState is the new state of the window.
Prepared By: Asst. Prof. Sejal Jadav
ļ¶ The methods of WindowEvent are:
Window getWindow( )
ā€¢ It returns the Window object that generated window the event.
Window getOppositeWindow()
ā€¢ It returns the opposite window that a focus event has been generated.
Prepared By: Asst. Prof. Sejal Jadav
int getOldState()
ā€¢ It returns the previous state of the window.
int getNewState()
ā€¢ It returns the new state of the window.
Prepared By: Asst. Prof. Sejal Jadav
Q:15) The WindowListener Interface:
ā€¢ This interface has seven methods.
void windowActivated(WindowEvent we)
ā€¢ This method is called when the window is activated.
void windowDeactivated(WindowEvent we)
ā€¢ This method is called when the window is deactivated.
Prepared By: Asst. Prof. Sejal Jadav
void windowClosed(WindowEvent we)
ā€¢ This method is called when the window has been closed.
void windowClosing(WindowEvent we)
ā€¢ This method is called when the window is being closed.
void windowOpened(WindowEvent we)
ā€¢ This method is called when the window has been opened.
Prepared By: Asst. Prof. Sejal Jadav
void windowIconified(WindowEvent we)
ā€¢ This method is called when the window is minimized.
void windowDeiconified(WindowEvent we)
ā€¢ This method is called when the window is restored.
ā€¢ Example: WindowExample.java
Prepared By: Asst. Prof. Sejal Jadav
Q: 15) The WindowFocusListener Interface:
void windowGainedFocus(WindowEvent we)
ā€¢ This is called when a window gains the input focus.
void windowLostFocus(WindowEvent we)
ā€¢ This is called when a window loses the input focus.
ā€¢ Example: WindowFocusListenerEx.java
Prepared By: Asst. Prof. Sejal Jadav
Q: Java WindowAdapter Example [page-22]
ā€¢ The class WindowAdapter is an abstract (adapter) class for receiving
window events.
ā€¢ All methods of this class are empty. This class is convenience class for
creating listener objects.
Prepared By: Asst. Prof. Sejal Jadav
ļ¶ Class declaration
ā€¢ Following is the declaration for java.awt.event.WindowAdapter class:
Public abstract class WindowAdapter
Extends Object
Implements
WindowListener,WindowStateListener,WindowFocusListener
Prepared By: Asst. Prof. Sejal Jadav
ā€¢ Dispose(): method :JFrame window to be destroyed and cleaned up by
the operating system.
ā€¢ Example: AdapterExample1.java
Prepared By: Asst. Prof. Sejal Jadav
Q-14 Explain Source of Events.
ā€¢ Source of events are:
Button
ā€¢ It generates action events (ActionEvent class) when the button is pressed.
Checkbox
ā€¢ It generates item events (ItemEvent class) when the check box is checked or
unchecked.
Prepared By: Asst. Prof. Sejal Jadav
Choice
ā€¢ It generates item events (ItemEvent class) when the item is changed in the
choice.
List
ā€¢ It can generateaction events as well as item events.When an item is double-
clicked, it generates ActionEvent and it generates ItemEvent when an item is
selected or deselected in the list.
Prepared By: Asst. Prof. Sejal Jadav
Menu Item
ā€¢ It can generate action events as well as item events. It generates action events
when an menu item is selected from a menu and generates an item event
when a checkable menu item is selected or deselected.
Scrollbar
ā€¢ It generates adjustment events (AdjustmentEvent class) when the scroll bar
is adjusted.
Prepared By: Asst. Prof. Sejal Jadav
Text controls such as text field, text area
ā€¢ It generates text events when the user enters a character into text field
or text area.
Window
ā€¢ It generates window events when a window is activated, opened, closed
etc.
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
Prepared By: Asst. Prof. Sejal Jadav
112

More Related Content

Similar to Programming Java Concept of Event Handling

event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxGood657694
Ā 
Events1
Events1Events1
Events1Nuha Noor
Ā 
2011 py con
2011 py con2011 py con
2011 py conEing Ong
Ā 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
Ā 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Javababak danyal
Ā 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024nehakumari0xf
Ā 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024kashyapneha2809
Ā 
Eclipse Training - SWT & JFace
Eclipse Training - SWT & JFaceEclipse Training - SWT & JFace
Eclipse Training - SWT & JFaceLuca D'Onofrio
Ā 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And DrupalPeter Arato
Ā 
Java gui event
Java gui eventJava gui event
Java gui eventSoftNutx
Ā 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Kernel Training
Ā 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and ClassesIntro C# Book
Ā 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design Rakesh Jha
Ā 

Similar to Programming Java Concept of Event Handling (20)

09events
09events09events
09events
Ā 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
Ā 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
Ā 
JAVA (UNIT 5)
JAVA (UNIT 5)JAVA (UNIT 5)
JAVA (UNIT 5)
Ā 
Events1
Events1Events1
Events1
Ā 
2011 py con
2011 py con2011 py con
2011 py con
Ā 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
Ā 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
Ā 
Java-Events
Java-EventsJava-Events
Java-Events
Ā 
EventHandling.pptx
EventHandling.pptxEventHandling.pptx
EventHandling.pptx
Ā 
Lecture 18
Lecture 18Lecture 18
Lecture 18
Ā 
Java 101
Java 101Java 101
Java 101
Ā 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
Ā 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
Ā 
Eclipse Training - SWT & JFace
Eclipse Training - SWT & JFaceEclipse Training - SWT & JFace
Eclipse Training - SWT & JFace
Ā 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
Ā 
Java gui event
Java gui eventJava gui event
Java gui event
Ā 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
Ā 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
Ā 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design
Ā 

More from Jadavsejal

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassJadavsejal
Ā 
C++ unit-2-part-3
C++ unit-2-part-3C++ unit-2-part-3
C++ unit-2-part-3Jadavsejal
Ā 
C++ unit-2-part-2
C++ unit-2-part-2C++ unit-2-part-2
C++ unit-2-part-2Jadavsejal
Ā 
C++ unit-2-part-1
C++ unit-2-part-1C++ unit-2-part-1
C++ unit-2-part-1Jadavsejal
Ā 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15Jadavsejal
Ā 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14Jadavsejal
Ā 
C++ unit-1-part-13
C++ unit-1-part-13C++ unit-1-part-13
C++ unit-1-part-13Jadavsejal
Ā 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12Jadavsejal
Ā 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11Jadavsejal
Ā 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10Jadavsejal
Ā 
C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9Jadavsejal
Ā 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8Jadavsejal
Ā 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7Jadavsejal
Ā 
C++ unit-1-part-6
C++ unit-1-part-6C++ unit-1-part-6
C++ unit-1-part-6Jadavsejal
Ā 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5Jadavsejal
Ā 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4Jadavsejal
Ā 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2Jadavsejal
Ā 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3Jadavsejal
Ā 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1Jadavsejal
Ā 
05_system architecture
05_system architecture05_system architecture
05_system architectureJadavsejal
Ā 

More from Jadavsejal (20)

Programming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone ClassProgramming with Java Concept: Java TimeZone Class
Programming with Java Concept: Java TimeZone Class
Ā 
C++ unit-2-part-3
C++ unit-2-part-3C++ unit-2-part-3
C++ unit-2-part-3
Ā 
C++ unit-2-part-2
C++ unit-2-part-2C++ unit-2-part-2
C++ unit-2-part-2
Ā 
C++ unit-2-part-1
C++ unit-2-part-1C++ unit-2-part-1
C++ unit-2-part-1
Ā 
C++ unit-1-part-15
C++ unit-1-part-15C++ unit-1-part-15
C++ unit-1-part-15
Ā 
C++ unit-1-part-14
C++ unit-1-part-14C++ unit-1-part-14
C++ unit-1-part-14
Ā 
C++ unit-1-part-13
C++ unit-1-part-13C++ unit-1-part-13
C++ unit-1-part-13
Ā 
C++ unit-1-part-12
C++ unit-1-part-12C++ unit-1-part-12
C++ unit-1-part-12
Ā 
C++ unit-1-part-11
C++ unit-1-part-11C++ unit-1-part-11
C++ unit-1-part-11
Ā 
C++ unit-1-part-10
C++ unit-1-part-10C++ unit-1-part-10
C++ unit-1-part-10
Ā 
C++ unit-1-part-9
C++ unit-1-part-9C++ unit-1-part-9
C++ unit-1-part-9
Ā 
C++ unit-1-part-8
C++ unit-1-part-8C++ unit-1-part-8
C++ unit-1-part-8
Ā 
C++ unit-1-part-7
C++ unit-1-part-7C++ unit-1-part-7
C++ unit-1-part-7
Ā 
C++ unit-1-part-6
C++ unit-1-part-6C++ unit-1-part-6
C++ unit-1-part-6
Ā 
C++ unit-1-part-5
C++ unit-1-part-5C++ unit-1-part-5
C++ unit-1-part-5
Ā 
C++ unit-1-part-4
C++ unit-1-part-4C++ unit-1-part-4
C++ unit-1-part-4
Ā 
C++ unit-1-part-2
C++ unit-1-part-2C++ unit-1-part-2
C++ unit-1-part-2
Ā 
C++ unit-1-part-3
C++ unit-1-part-3C++ unit-1-part-3
C++ unit-1-part-3
Ā 
C++-Unit-1-Part-1
C++-Unit-1-Part-1C++-Unit-1-Part-1
C++-Unit-1-Part-1
Ā 
05_system architecture
05_system architecture05_system architecture
05_system architecture
Ā 

Recently uploaded

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
Ā 
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
Ā 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
Ā 
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
Ā 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
Ā 
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdfssuser54595a
Ā 
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
Ā 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
Ā 
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
Ā 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
Ā 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
Ā 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
Ā 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
Ā 
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
Ā 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
Ā 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
Ā 

Recently uploaded (20)

Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
Ā 
Model Call Girl in Bikash Puri Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Bikash Puri  Delhi reach out to us at šŸ”9953056974šŸ”Model Call Girl in Bikash Puri  Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Bikash Puri Delhi reach out to us at šŸ”9953056974šŸ”
Ā 
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
Ā 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
Ā 
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
Ā 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
Ā 
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAŠ”Y_INDEX-DM_23-1-final-eng.pdf
Ā 
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at šŸ”9953056974šŸ”
Ā 
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
Ā 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
Ā 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
Ā 
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
Ā 
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
Ā 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
Ā 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
Ā 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
Ā 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
Ā 
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
Ā 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
Ā 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
Ā 

Programming Java Concept of Event Handling

  • 1. Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav 1
  • 2. Prepared By: Asst. Prof. Sejal Jadav Unit-5 CS ā€“ 19 : Programming with Java UNIT ā€“ 5 GUI using SWING, Event Handling B.C.A & B.SC.(IT) ā€“ 4
  • 3. Prepared By: Asst. Prof. Sejal Jadav Event Handling Unit-5(Part-2)
  • 4. Prepared By: Asst. Prof. Sejal Jadav Event Classes and Listener Interfaces
  • 5. Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Event Classes Listener Interfaces ActionEvent ActionListener ItemEvent ItemListener FocusEvent FocusListener MouseEvent MouseListener and MouseMotionListener MouseWheelEvent MouseWheelListener TextEvent TextListener KeyEvent KeyListener
  • 6. Prepared By: Asst. Prof. Sejal Jadav Q-8 Explain FocusEvent Class. ā€¢ A FocusEvent is generated when a component gains or loses input focus. FOCUS_GAINED ā€¢ It is set when the component gains the input focus. FOCUS_LOST ā€¢ It is set when the component loses the input focus.
  • 7. Prepared By: Asst. Prof. Sejal Jadav ā€¢ FocusEvent is a subclass of ComponentEvent and has these constructors: ā€¢ FocusEvent(Component src, int type) ā€¢ FocusEvent(Component src, int type, boolean temporaryFlag) ā€¢ Here, src is a reference to the component that generated this event. The type of the event is specified by type. The argument temporaryFlag is set to true if the focus event is temporary. Otherwise, it is set to false.
  • 8. Prepared By: Asst. Prof. Sejal Jadav ā€¢ (A temporary focus event occurs as a result of another user interface operation. ā€¢ For example, assume that the focus is in a text field. If the user moves the mouse to adjust a scroll bar, the focus is temporarily lost.)
  • 9. Prepared By: Asst. Prof. Sejal Jadav ā€¢ The isTemporary( ) method indicates if this focus change is temporary. Its form is shown here: boolean isTemporary( ) ā€¢ The method returns true if the change is temporary. Otherwise, it returns false.
  • 10. Prepared By: Asst. Prof. Sejal Jadav Q: 15 The FocusListener Interface: ā€¢ This interface defines two methods which are called when a component gets or loses the focus. void focusGained(FocusEvent fe) void focusLost(FocusEvent fe) ā€¢ Example: AwtListenerDemo.java
  • 11. Prepared By: Asst. Prof. Sejal Jadav Q: Java Adapter Classes ā€¢ Java adapter classes provide the default implementation of listener interfaces. ā€¢ If you inherit the adapter class, you will not be forced to provide the implementation of all the methods of listener interfaces. ā€¢ So it saves code.
  • 12. Prepared By: Asst. Prof. Sejal Jadav Swing Focus Adapter ā€¢ 1. FocusAdapter class is an abstract adapter class in Java Swing. ā€¢ 2. FocusAdapter class is for receiving keyboard focus events. ā€¢ 3. Methods specified in FocusAdapter class are empty. ā€¢ 4. FocusAdapter class exists as convenience(suitable) for creating listener objects
  • 13. Prepared By: Asst. Prof. Sejal Jadav Class declaration ā€¢ Below is the declaration for java.awt.event.FocusAdapter class ā€“ public abstract class FocusAdapter extends Object implements FocusListener
  • 14. Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Class constructors: FocusAdapter() Class methods: No. Method Return Type Parameter Invoked when 1 focusGained() void FocusEvent component gains the keyboard focus 2 focusLost() void FocusEvent component loses the keyboard focus
  • 15. Prepared By: Asst. Prof. Sejal Jadav Methods inherited: ā€¢ This class inherits methods from the following classes: java.lang.Object ļ¶Swing Focus Adapter Example: AdapterExample.java
  • 16. Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Event Classes Listener Interfaces ActionEvent ActionListener ItemEvent ItemListener FocusEvent FocusListener MouseEvent MouseListener and MouseMotionListener MouseWheelEvent MouseWheelListener TextEvent TextListener KeyEvent KeyListener
  • 17. Prepared By: Asst. Prof. Sejal Jadav Q-10 Explain KeyEvent Class. ā€¢ A KeyEvent is generated when keyboard input occurs. There are three types of key events, which are identified by these integer constants: KEY_PRESSED ā€¢ It is set when a key is pressed in the keyboard. KEY_RELEASED ā€¢ It is set when a key is pressed in the keyboard.
  • 18. Prepared By: Asst. Prof. Sejal Jadav KEY_TYPED ā€¢ It is set when a printable key is pressed. The key such as ALT, CTRL, SHIFT, etc are not printable character.
  • 19. Prepared By: Asst. Prof. Sejal Jadav ā€¢ There are many other integer constants that are defined by KeyEvent. For example, VK_0 through VK_9 and VK_A through VK_Z define the ASCII equivalents of the numbers and letters. ā€¢ Here are some others:
  • 20. Prepared By: Asst. Prof. Sejal Jadav Here are some others: ā€¢ The VK constants specify virtual key codes and are independent of any modifiers, such as control, shift, or alt. VK_ENTER VK_ESCAPE VK_CANCEL VK_UP VK_DOWN VK_LEFT VK_RIGHT VK_PAGE_DOWN VK_PAGE_UP VK_SHIFT VK_ALT VK_CONTROL
  • 21. Prepared By: Asst. Prof. Sejal Jadav ā€¢ KeyEvent is a subclass of InputEvent. Here are two of its constructors: KeyEvent(Component src, int type, long when, int modifiers, int code) KeyEvent(Component src, int type, long when, int modifiers, int code, char ch)
  • 22. Prepared By: Asst. Prof. Sejal Jadav ā€¢ Here, src is a reference to the component that generated the event. The type of the event is specified by type. ā€¢ The system time at which the key was pressed is passed in when. ā€¢ The modifiers argument indicates which modifiers were pressed when this key event occurred.
  • 23. Prepared By: Asst. Prof. Sejal Jadav ā€¢ The virtual key code, such as VK_UP, VK_A, and so forth, is passed in code. ā€¢ The character equivalent (if one exists) is passed in ch. ā€¢ If no valid character exists, then ch contains CHAR_UNDEFINED. ā€¢ For KEY_TYPED events, code will contain VK_UNDEFINED.
  • 24. Prepared By: Asst. Prof. Sejal Jadav The most commonly used methods of KeyEvent class are: char getKeyChar( ) ā€¢ It returns the character that was pressed entered. getKeyCode( ) ā€¢ It returns the code of the key pressed.
  • 25. Prepared By: Asst. Prof. Sejal Jadav Q: 15) The KeyListener Interface: ā€¢ This interface defines three methods. void keyPressed(KeyEvent ke) ā€¢ This method is called when a keyboard key is pressed. void keyReleased(KeyEvent ke) ā€¢ This method is called when a keyboard key is released. void keyTyped(KeyEvent ke) ā€¢ This method is called when a printable character key is pressed.
  • 26. Prepared By: Asst. Prof. Sejal Jadav ā€¢ Example: KeyEvents.java
  • 27. Prepared By: Asst. Prof. Sejal Jadav Java KeyAdapter Example [page- 24] ā€¢ The class KeyAdapter is an abstract (adapter) class for receiving keyboard events. ā€¢ All methods of this class are empty. This class is convenience class for creating listener objects.
  • 28. Prepared By: Asst. Prof. Sejal Jadav ļ± Class declaration ā€¢ Following is the declaration for java.awt.event.KeyAdapter class: public abstract class KeyAdapter extendsObject implements KeyListener ā€¢ Example: KeyAdapterExample.java
  • 29. Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Event Classes Listener Interfaces ActionEvent ActionListener ItemEvent ItemListener FocusEvent FocusListener MouseEvent MouseListener and MouseMotionListener MouseWheelEvent MouseWheelListener TextEvent TextListener KeyEvent KeyListener
  • 30. Prepared By: Asst. Prof. Sejal Jadav Q-11 Explain MouseEvent Class. ā€¢ There are seven types of mouse events. ā€¢ The MouseEvent class defines the following integer constants that can be used to identify them: MOUSE_CLICKED ā€¢ The user clicked the mouse. MOUSE_DRAGGED ā€¢ The user dragged the mouse.
  • 31. Prepared By: Asst. Prof. Sejal Jadav MOUSE_ENTERED ā€¢ The mouse entered a component. MOUSE_EXITED ā€¢ The mouse exited from a component. MOUSE_MOVED ā€¢ The mouse moved. MOUSE_PRESSED ā€¢ The mouse was pressed. MOUSE_RELEASED ā€¢ The mouse was released.
  • 32. Prepared By: Asst. Prof. Sejal Jadav ā€¢ MouseEvent is a subclass of InputEvent. Here is one of its constructors. MouseEvent(Component src, int type, long when, int modifiers, int x, int y, int clickCount, boolean opensPopup)
  • 33. Prepared By: Asst. Prof. Sejal Jadav MouseEvent(Component src, int type, long when, int modifiers, int x, int y, int clickCount, boolean opensPopup) ā€¢ Here, src is a reference to the component that generated the event. ā€¢ The type is the type of the event and time specifies the system time at which the event was generated. ā€¢ The modifiers parameter specifies any modifier keys that were pressed during the event. ā€¢ The x and y are the coordinates of the mouse location. ā€¢ The clickCount stores the number of mouse click. ā€¢ When opensPopup is true, it specifies that any popup menu was opened after the mouse event.
  • 34. Prepared By: Asst. Prof. Sejal Jadav ā€¢ The commonly used methods of MouseEvent are: int getX( ) ā€¢ It returns the x coordinate of the mouse cursor. int getY( ) ā€¢ It returns the y coordinate of the mouse cursor.
  • 35. Prepared By: Asst. Prof. Sejal Jadav void translatePoint(int x, int y) ā€¢ It translate the mouse pointer to specified x and y location. int getClickCount( ) ā€¢ It returns the number of mouse pointer clicked. For example 2 for double click. boolean isPopupTrigger( ) ā€¢ It returns the true if any popup was opened after the mouse event.
  • 36. Prepared By: Asst. Prof. Sejal Jadav Q: 15 ) The MouseListener Interface: ā€¢ This interface defines five methods which are called when a mouse event is generated These methods are: void mouseClicked(MouseEvent me) ā€¢ This method is called when the mouse button is clicked. void mouseEntered(MouseEvent me) ā€¢ This method is called when the mouse button is entered into a component.
  • 37. Prepared By: Asst. Prof. Sejal Jadav void mouseExited(MouseEvent me) ā€¢ This method is called when the mouse button is exited from a component. void mousePressed(MouseEvent me) ā€¢ This method is called when the mouse button is pressed. void mouseReleased(MouseEvent me) ā€¢ This method is called when the mouse button is released.
  • 38. Prepared By: Asst. Prof. Sejal Jadav Q: 15) The MouseMotionListener Interface: ā€¢ This interface defines two methods. void mouseDragged(MouseEvent me) ā€¢ This method is called the mouse is dragged. void mouseMoved(MouseEvent me) ā€¢ This method is called when mouse pointer is moved.
  • 39. Prepared By: Asst. Prof. Sejal Jadav Q-15) The MouseWheelListener Interface: ā€¢ It has one method: void mouseWheelMoved(MouseWheelEvent mwe) ā€¢ This method is called when the wheel of the mouse is moved. ā€¢ Example: Q-16 Mouse Handling Program: ā€¢ MouseEvents.java
  • 40. Prepared By: Asst. Prof. Sejal Jadav Q: Java MouseAdapter Example [page: 23] ā€¢ The class MouseAdapter is an abstract (adapter) class for receiving mouse events. ā€¢ All methods of this class are empty. This class is convenience class for creating listener objects.
  • 41. Prepared By: Asst. Prof. Sejal Jadav ā€¢ Class declaration: ā€¢ Following is the declaration for java.awt.event.MouseAdapter class: Public abstract class MouseAdapter extends Object implements MouseListener,MouseWheelListener,MouseMotionListener
  • 42. Prepared By: Asst. Prof. Sejal Jadav ā€¢ Example: MouseAdapterExample.java
  • 43. Prepared By: Asst. Prof. Sejal Jadav Q: Java MouseMotionAdapter Example [page:23] ā€¢ The class MouseMotionAdapter is an abstract (adapter) class for receiving mouse motion events. ā€¢ All methods of this class are empty. This class is convenience class for creating listener objects.
  • 44. Prepared By: Asst. Prof. Sejal Jadav ļ¶ Class Declaration ā€¢ Following is the declaration for java.awt.event.MouseMotionAdapter class āˆ’ public abstract class MouseMotionAdapter extends Object implements MouseMotionListener ā€¢ Example:MouseMotionAdapterExample.java
  • 45. Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Event Classes Listener Interfaces ActionEvent ActionListener ItemEvent ItemListener FocusEvent FocusListener MouseEvent MouseListener and MouseMotionListener MouseWheelEvent MouseWheelListener TextEvent TextListener KeyEvent KeyListener
  • 46. Prepared By: Asst. Prof. Sejal Jadav Q-12 Explain TextEvent Class. ā€¢ The TextEvent is generated when user inputs some text into a text field or a text area. It has one integer constant. TEXT_VALUE_CHANGED ā€¢ It is set when the text in a text field or a text area changed. ā€¢ Its constructor is: TextEvent(Object source,int type) ā€¢ Here source is the object that generated this event. ā€¢ The type is the type event which can be TEXT_VALUE_CHANGED.
  • 47. Prepared By: Asst. Prof. Sejal Jadav Q:15) The TextListener Interface: ā€¢ This interface ha one method: void textChanged(TextEvent te) ā€¢ It is called when the text of a text area or text field is changed. ā€¢ Example: JavaExampleTextEvent.java
  • 48. Prepared By: Asst. Prof. Sejal Jadav Q-13 Explain WindowEvent Class. ā€¢ The WindowEvent class handles the events related to a window and it is a subclass of ComponentEvent class. ā€¢ There are ten types of window events constant: WINDOW_ACTIVATED ā€¢ The window was activated.
  • 49. Prepared By: Asst. Prof. Sejal Jadav WINDOW_DEACTIVATED ā€¢ The window was deactivated. WINDOW_CLOSED ā€¢ The window has been closed. WINDOW_CLOSING ā€¢ The user requested that the window be closed.
  • 50. Prepared By: Asst. Prof. Sejal Jadav WINDOW_OPENED ā€¢ The window was opened. WINDOW_GAINED_FOCUS ā€¢ The window gained input focus. WINDOW_LOST_FOCUS ā€¢ The window lost input focus.
  • 51. Prepared By: Asst. Prof. Sejal Jadav WINDOW_ICONIFIED ā€¢ The window was iconified. Ex it is minimized WINDOW_DEICONIFIED ā€¢ The window was deiconified. Ex it is restored WINDOW_STATE_CHANGED ā€¢ It is set when the state of the window is changed.
  • 52. Prepared By: Asst. Prof. Sejal Jadav ā€¢ The constructors of WindowEvent are: ā€¢ WindowEvent(Window source, int type) ā€¢ WindowEvent(Window source, int type, Window other) ā€¢ WindowEvent(Window source, int type, int oldState, int newState) ā€¢ WindowEvent(Window source, int type, Window other, int oldState, int newState)
  • 53. Prepared By: Asst. Prof. Sejal Jadav ā€¢ Here, source is the window object that generated the window event. ā€¢ The type specifies the type of event such as WINDOW_CLOSING etc. ā€¢ The other specifies the opposite window when a focus event occurs. ā€¢ The oldState is the previous state of the event. ā€¢ The newState is the new state of the window.
  • 54. Prepared By: Asst. Prof. Sejal Jadav ļ¶ The methods of WindowEvent are: Window getWindow( ) ā€¢ It returns the Window object that generated window the event. Window getOppositeWindow() ā€¢ It returns the opposite window that a focus event has been generated.
  • 55. Prepared By: Asst. Prof. Sejal Jadav int getOldState() ā€¢ It returns the previous state of the window. int getNewState() ā€¢ It returns the new state of the window.
  • 56. Prepared By: Asst. Prof. Sejal Jadav Q:15) The WindowListener Interface: ā€¢ This interface has seven methods. void windowActivated(WindowEvent we) ā€¢ This method is called when the window is activated. void windowDeactivated(WindowEvent we) ā€¢ This method is called when the window is deactivated.
  • 57. Prepared By: Asst. Prof. Sejal Jadav void windowClosed(WindowEvent we) ā€¢ This method is called when the window has been closed. void windowClosing(WindowEvent we) ā€¢ This method is called when the window is being closed. void windowOpened(WindowEvent we) ā€¢ This method is called when the window has been opened.
  • 58. Prepared By: Asst. Prof. Sejal Jadav void windowIconified(WindowEvent we) ā€¢ This method is called when the window is minimized. void windowDeiconified(WindowEvent we) ā€¢ This method is called when the window is restored. ā€¢ Example: WindowExample.java
  • 59. Prepared By: Asst. Prof. Sejal Jadav Q: 15) The WindowFocusListener Interface: void windowGainedFocus(WindowEvent we) ā€¢ This is called when a window gains the input focus. void windowLostFocus(WindowEvent we) ā€¢ This is called when a window loses the input focus. ā€¢ Example: WindowFocusListenerEx.java
  • 60. Prepared By: Asst. Prof. Sejal Jadav Q: Java WindowAdapter Example [page-22] ā€¢ The class WindowAdapter is an abstract (adapter) class for receiving window events. ā€¢ All methods of this class are empty. This class is convenience class for creating listener objects.
  • 61. Prepared By: Asst. Prof. Sejal Jadav ļ¶ Class declaration ā€¢ Following is the declaration for java.awt.event.WindowAdapter class: Public abstract class WindowAdapter Extends Object Implements WindowListener,WindowStateListener,WindowFocusListener
  • 62. Prepared By: Asst. Prof. Sejal Jadav ā€¢ Dispose(): method :JFrame window to be destroyed and cleaned up by the operating system. ā€¢ Example: AdapterExample1.java
  • 63. Prepared By: Asst. Prof. Sejal Jadav Q-14 Explain Source of Events. ā€¢ Source of events are: Button ā€¢ It generates action events (ActionEvent class) when the button is pressed. Checkbox ā€¢ It generates item events (ItemEvent class) when the check box is checked or unchecked.
  • 64. Prepared By: Asst. Prof. Sejal Jadav Choice ā€¢ It generates item events (ItemEvent class) when the item is changed in the choice. List ā€¢ It can generateaction events as well as item events.When an item is double- clicked, it generates ActionEvent and it generates ItemEvent when an item is selected or deselected in the list.
  • 65. Prepared By: Asst. Prof. Sejal Jadav Menu Item ā€¢ It can generate action events as well as item events. It generates action events when an menu item is selected from a menu and generates an item event when a checkable menu item is selected or deselected. Scrollbar ā€¢ It generates adjustment events (AdjustmentEvent class) when the scroll bar is adjusted.
  • 66. Prepared By: Asst. Prof. Sejal Jadav Text controls such as text field, text area ā€¢ It generates text events when the user enters a character into text field or text area. Window ā€¢ It generates window events when a window is activated, opened, closed etc.
  • 67. Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav Prepared By: Asst. Prof. Sejal Jadav 112