CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades

Events

Events
Handle events
Two types

The two types of Java events

  • Two types of events exist in Java: semantic events and low-level events.
  • A semantic event is related to a specific component such as clicking a button or selecting an item from a list.
  • Low-level events are less specific, like clicking a mouse button, pressing a key on the keyboard, or closing a window.
  • Most events and listeners are stored in the java.awt.event package, but some of the newer events and listeners are stored in the javax.swing.event package.
  • Some user actions create more than one event. You can use listeners to respond to any of them.

Semantic events

 
Action Event object Listener interface
Button clicked ActionEvent ActionListener
Combo box item selected ActionEvent
ItemEvent
ActionListener
ItemListener
List item selected ListSelectionEvent ListSelectionListener
Text component changed DocumentEvent DocumentListener
Radio button selected ActionEventActionListener
ItemEvent ItemListener
Check box selected ActionEvent
ItemEvent
ActionListener
ItemListener
Scroll bar repositioned AdjustmentEvent AdjustmentListener

Low-level events

Action Event object Listener interface
Window changed WindowEvent WindowListener
Focus changed FocusEvent FocusListener
Key pressed KeyEvent KeyListener
Mouse moved or clicked MouseEvent MouseListener
Previous | Java event model | Two types | Structure event handling | Panel | Separate class | Inner class | Separate event listeners | Anonymous inner classes | Next