Mouse and Key Events - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Mouse and Key Events

Description:

The Delegation Model. Event-generating Objects send ... NOTE: here, I do not implement the listener. ... An instance of my subclass serves as the listener. ... – PowerPoint PPT presentation

Number of Views:35
Avg rating:3.0/5.0
Slides: 8
Provided by: mikem52
Category:
Tags: events | key | listener | mouse | the

less

Transcript and Presenter's Notes

Title: Mouse and Key Events


1
Mouse and Key Events
  • Mostly corresponds
  • with
  • Ch14 pp 477-482

2
The Delegation Model
Event-generating Objects send Events to Listener
Objects
Each event-generating object (usually a
component) maintains a set of listeners for each
event that it generates. To be on the list, a
listener object must register itself with the
event-generating object. Listeners have
event-handling methods that respond to the event.
3
Event Classes
Note input events (mouse, key) are considered to
be low-level events. Any component can generate
low-level events, and they do not capture meaning
of the component. This is contrasted with
high-level events (such as ActionEvent) which are
semantic in that they convey some meaning of the
nature of the event.
4
An example of Mouse event handling
MouseListener methods
MouseMotionListener methods
5
An example of Key event handling
Key-related listener interface
Note the wide variety of key codes that can be
identified by the KeyEvent.
6
AWT Event Adapter Classes
  • ComponentAdapter
  • ContainerAdapter
  • FocusAdapter
  • KeyAdapter
  • MouseAdapter
  • MouseMotionAdapter

All are in the java.awt.event package All are
derived from Object in the java.lang package Each
implements an associated Listener interface
Note interface implementations require that ALL
abstract methods be definedAdapters take care of
that for you in case you only want to define a
subset of the methods for a listener
7
An example of Mouse event handling via a
MouseAdapter class
NOTE here, I do not implement the listener.
Instead, I create a subclass of the MouseAdapter
class, and override only the methods I need. An
instance of my subclass serves as the listener.
Write a Comment
User Comments (0)
About PowerShow.com