0% found this document useful (0 votes)
64 views6 pages

3.1 Delegation Event Model

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views6 pages

3.1 Delegation Event Model

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Chapter 3

Event Handling Marks-12

Unit Outcome-
1. Use delegation event model to develop event driven program for the given
problem
2. Use relevant AWT/Swing components to handle the given event
3. Use adapter classes in java program to solve the given problem
4. Use inner classes in java program to solve the given probelm
Delegation event model
- the delegation event model is based on the Event Source and Event Listeners.
-Changing the state of an object is known as an event.
-For Example : Pressing a button, Entering a character in Textbox, Clicking or Dragging
a mouse, etc.

Events : An event is a change in state of an object.


Events Source : Event source is an object that generates an event.
Listeners : A listener is an object that listens to the event. A listener gets notified
when an event occurs.
Event class
-It is the root event class for all AWT events.
-This class is defined in java.awt package.

Constructor- EventObject(Object src)

Methods-
1. int getID( )-determine the type of the event.
2. Object getSource( )- returns the source of the event.
Event Classes Description Listener Interface
ActionEvent generated when button is pressed, menu-item is selected, list- ActionListener
item is double clicked
MouseEvent generated when mouse is dragged, moved,clicked,pressed or MouseListener
released and also when it enters or exit a component

KeyEvent generated when input is received from keyboard KeyListener


ItemEvent generated when check-box or list item is clicked ItemListener
TextEvent generated when value of textarea or textfield is changed TextListener
MouseWheelEvent generated when mouse wheel is moved MouseWheelListener
WindowEvent generated when window is activated, deactivated, deiconified, WindowListener
iconified, opened or closed
ComponentEvent generated when component is hidden, moved, resized or set ComponentEventListener
visible
ContainerEvent generated when component is added or removed from ContainerListener
container
AdjustmentEvent generated when scroll bar is manipulated AdjustmentListener
FocusEvent generated when component gains or loses keyboard focus FocusListener
Different listeners and methods
Listener Interface Methods
ActionListener public void actionPerformed(ActionEvent ae)
AdjustmentListener public void adjustmentValueChanged(AdjustmentEvent ae)
ComponentListener public void componentResized(ComponentEvent ce)
public void componentMoved(ComponentEvent ce)
public void componentShown(ComponentEvent ce)
public void componentHidden(ComponentEvent ce)

ContainerListener public void componentAdded(ContainerEvent ce)


public void componentRemoved(ContainerEvent ce)
FocusListener public void focusGained(FocusEvent fe)
public void focusLost(FocusEvent fe)
ItemListener public void itemStateChanged(ItemEvent ie)
KeyListener public void keyPressed(KeyEvent ke)
public void keyReleased(KeyEvent ke)
public void keyTyped(KeyEvent ke)
Different listeners and methods
Listener Interface Methods
MouseListener public void mouseClicked(MouseEvent me)
public void mouseEntered(MouseEvent me)
public void mouseExited(MouseEvent me)
public void mousePressed(MouseEvent me)
public void mouseReleased(MouseEvent me)

MouseMotionListener public void mouseDragged(MouseEvent me)


public void mouseMoved(MouseEvent me)
TextListener public void textValueChanged(TextEvent te)
WindowListener public void windowActivated(WindowEvent we)
public void windowClosed(WindowEvent we)
public void windowClosing(WindowEvent we)
public void windowDeactivated(WindowEvent we)
public void windowDeiconified(WindowEvent we)
public void windowIconified(WindowEvent we)
public void windowOpened(WindowEvent we)

You might also like