AWT - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

AWT

Description:

... with the system. ... The program must register this object as an action listener on ... ActionEvent object that gives information about the event and ... – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 15
Provided by: gar59
Category:
Tags: awt | register

less

Transcript and Presenter's Notes

Title: AWT


1
AWT
  • Responding to Events

2
Terminology
  • Delegation Event Model A source generates an
    event and notified the listeners that registered
    and requested to be notified when the event
    occurs. You only receive events you want to
    process.
  • Event A user interaction with the system. An
    Event object described a state change in the
    Source object that generated of the event.
  • Listener An object that wants to be notified
    with a certain event occurs. A Listener must
    register with a Source to receive notification of
    an event.
  • Source An object that generates an event.

3
AWTEvent class
4
Event Handling
  • Every time the user types a character or pushes a
    mouse button, an event occurs.
  • Any object can be notified of the event. All it
    has to do is implement the appropriate interface
    and be registered as an event listener on the
    appropriate event source.
  • Swing components can generate many kinds of
    events. You will see a few examples on the next
    few slides.

5
Event Driven Programs
6
Event Handling Process
7
Event Handling Process
  • To detect when the user clicks an on-screen
    button (or does the keyboard equivalent), a
    program must have an object that implements the
    ActionListener interface.
  • The program must register this object as an
    action listener on the button (the event source),
    using the addActionListener method.
  • When the user clicks the on-screen button, the
    button fires an action event. This results in the
    invocation of the action listener's
    actionPerformed method (the only method in the
    ActionListener interface).
  • The single argument to the method is an
    ActionEvent object that gives information about
    the event and its source.

8
Event Handling Process
9
Event Handling
10
Event Handling
  • Each event is represented by an object that gives
    information about the event and identifies the
    event source.
  • Event sources are typically components, but other
    kinds of objects can also be event sources.
  • As the following figure shows, each event source
    can have multiple listeners registered on it.
    Conversely, a single listener can register with
    multiple event sources.
  • From Suns Java Tutorial

11
Event Source Event Generated
12
Low-Level Event Classes
  • There are four kinds of low-level events that you
    can elect to handle in your programs.
  • They are represented by the following classes in
    the java.awt.event package

13
Low-Level Event Classes
14
Looks Like Times Up!
  • What so soon?
Write a Comment
User Comments (0)
About PowerShow.com