0% found this document useful (0 votes)
330 views

Java Event Handling

This document discusses Java event handling. It explains that event handling controls what happens when an event occurs by changing the state of an object. It describes the delegation event model where a source generates an event that is handled by a listener. It provides examples of how to write event handlers for different types of events, including action events, item events, key events, mouse motion events, and mouse events by overriding specific methods. The examples demonstrate how to register listeners and write code to respond to different types of events in Java.

Uploaded by

Dipendra Km
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
330 views

Java Event Handling

This document discusses Java event handling. It explains that event handling controls what happens when an event occurs by changing the state of an object. It describes the delegation event model where a source generates an event that is handled by a listener. It provides examples of how to write event handlers for different types of events, including action events, item events, key events, mouse motion events, and mouse events by overriding specific methods. The examples demonstrate how to register listeners and write code to respond to different types of events in Java.

Uploaded by

Dipendra Km
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

JAVA EVENT

HANDLING
Java Event Handling

■ Event Handling is the change in the state of object or source.


■ Example:
– Event Handling is the mechanism that controls the event and decide what should
happen if an event occurs.
Delegation event model

■ Delegation Event Model Benefits of DEM model


- User interface logic is completely different
From event handler logic

■ Source Listener
is an object Event Handler
on which event generate response to event
occur

Event register
Click here
Java code
State change
Event Handler example

■ ActionListener Example
 It is an interface
 Used to handle events caused by source like button, menu item etc
 Override the actionPerformed(ActionEvent e)
ItemListener Example

■ Used for radioButton, list, choice and checkbox AWT control


■ Override the public void itemStateChanged(ItemEvent ie)
■ Example
CheckBox c1 = new CheckBox(“sub”,null,false);
C1.addItemListener()
Public void itemStateChaged(ItemEvent ie){
if(c1.isSelected()){
}
}
KeyListener

■ Handles the events generated from keys of Keybord


■ Public void keyPressed(KeyEvent ke);
■ Public void keyTyped(KeyEvent ke);
■ Public void keyReleased(KeyEvent ke);
MouseMotionListener

■ Handles Event generated from Mouse


- Override the
public void mouseMoved(MouseEvent me)
Public void mouseDraged(MouseEvent me)
MouseListiner

■ Public void mousePressed(MouseEvent me)


■ Public void mouseClicked(MouseEvent me)
■ Public void mouseReleased(MouseEvent me)
■ Public void mouseEntered(MouseEvent me)
■ Public void mouseExited(MouseEvent me)

You might also like