2. Event Handling
Event Listener Interfaces and their Methods Event classes and their methods
ItemListener
• void itemStateChanged (ItemEvent ie)
ItemEvent
Generated when a check box or a list item is clicked; also occurs
when a choice selection is made or a checkable menu is selected or
deselected.
• Object getSource()
KeyListener
• void keyPressed (KeyEvent ke)
• void keyReleased (KeyEvent ke)
• void keyTyped (KeyEvent ke)
KeyEvent
Generated when input is received from the keyboard.
• Object getSource()
MouseMotionListener
• void mouseDragged (MouseEvent me)
• void mouseMoved (MouseEvent me) //no buttons have
been pushed
MouseEvent
Generated when the mouse is dragged, moved, clicked, pressed, or
released; also generated when the mouse enters or exits a
component.
• Object getSource()
MouseListener
• void mouseClicked (MouseEvent me) //pressed or
released on a component
• void mousePressed(MouseEvent me)
• void mouseReleased (MouseEvent me)
MouseEvent
Same as above.
Instructor: Tanzila Kehkashan
2
3. Event Handling
Event Listener Interfaces and their Methods Event classes and their methods
TextListener
• void textValueChanged (TextEvent te)
TextEvent
Generated when the value of a textarea or textfield is changed.
• Object getSource()
WindowListener
• void windowActivated (WindowEvent we)
• void windowClosed (WindowEvent we)
• void windowClosing (WindowEvent we)
• void windowDeactivated (WindowEvent we)
• void windowDeiconified (WindowEvent we) //from a
minimized to a normal state
• void windowIconified (WindowEvent we) //from a
normal to a minimized state
• void windowOpened (WindowEvent we)
WindowEvent
Generated when a window is activated, closed, deactivated,
deiconified, iconified, opened, or quit.
• Object getSource()
Instructor: Tanzila Kehkashan
3
7. ASSIGNMENT
Q#1: Write a program which has two buttons. After each click, the program
determines how many times that specific button has been clicked.
Q#2: Make online admission form of student in three steps.
• In 1st frame, get personal bio-data of student,
• In 2nd frame, get academic record of student, and
• In 3rd frame, display all the information of student you collected in previous two
frames.
Instructor: Tanzila Kehkashan
7
8. ASSIGNMENT
Write a program which consists of two drop down Lists and four buttons having
captions “>”, “>>”, “<”, “<<”. When user clicks on button “>”, selected item from
left list moves towards right list. Rest of three buttons work accordingly.
Instructor: Tanzila Kehkashan
8