Cup 6: AWT Event Handling - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

Cup 6: AWT Event Handling

Description:

events are sent to the program that owns the window in which ... activating, deactivating, closing, iconifying, etc. related to Window objects (and subclasses) ... – PowerPoint PPT presentation

Number of Views:100
Avg rating:3.0/5.0
Slides: 11
Provided by: timma87
Category:

less

Transcript and Presenter's Notes

Title: Cup 6: AWT Event Handling


1
Cup 6 AWT Event Handling
  • Special Topics Java

Dr. Tim Margush Department of Mathematics and
Computer Science The University of Akron
2
Event Handling Process
  • Operating System monitors keystrokes, mouse
    actions, and other events
  • events are sent to the program that owns the
    window in which the event occurred
  • Events in Java programs cause calls to the AWT
    library routines which create Event objects
  • These objects are then passed to methods in your
    program to handle the events

3
Listeners
  • Objects that must respond to events generally
    register one or more listeners
  • An add_X_Listener method does this
  • Components can handle their own events
  • A Listener is simply a class that implements
    certain methods
  • The methods are defined in an interface
  • Listeners extend java.util.EventListener

4
Event Classes
  • Low-Level Events
  • keyboard, mouse, window actions
  • Semantic Events
  • component-related (button click, scrollbar
    adjustment, menu operation)
  • Some system events cause multiple Java events
  • click button - causes both types of events

5
Low-Level Event Classes
  • FocusEvent
  • occurs when a component gets or loses the focus
  • MouseEvent
  • movement of the mouse or pressing mouse button
  • KeyEvent
  • keyboard
  • WindowEvent
  • activating, deactivating, closing, iconifying,
    etc.
  • related to Window objects (and subclasses)

6
Event Hierarchy
  • java.util.EventObject
  • java.awt.AWTEvent
  • java.awt.event.ComponentEvent
  • All events are subclassed from ComponentEvent and
    are located in the java.awt.event package
  • All events inherit getSource() from the top level

7
Low-Level Listeners
  • All listeners are in java.awt.event
  • There are Listener classes for each event type
  • WindowListener
  • MouseListener
  • MouseMotionListener
  • KeyListener
  • FocusListener

8
Adapter Classes
  • A class that implements all the methods of a
    Listener interface with empty bodies
  • By subclassing, you need only override methods
    you need to implement
  • There are adapter classes for all of the
    low-level listener interfaces
  • FocusAdapter
  • MouseAdapter
  • WindowAdapter
  • MouseMotionAdapter
  • KeyAdapter

9
Semantic Event Classes
  • ActionEvent
  • Button, List, MenuItem
  • TextEvent
  • TextArea, TextField
  • AdjustmentEvent
  • Scrollbar
  • ItemEvent
  • Checkbox
  • CheckboxMenuItem
  • Choice
  • List

10
Semantic Listeners
  • Each semantic event has a corresponding Listener
    interface
  • ActionListener
  • ItemListener
  • TextListener
  • AdjustmentListener
  • Each of these listener interfaces has only one
    method to be implemented
Write a Comment
User Comments (0)
About PowerShow.com