Event-Driven
Programming
Chapter 6
6
Event Sources and Listeners
An event is an object that signals
something has happened.
An event source is the object tha...
6
Mouse Events
Import the java.awt.event.* library
Implement the interface of the
MouseListener class
For MouseListener th...
6
MouseClick.java
Applet responds to
mouseClicked
events by drawing
ovals in the applet
window
6
Creating a Timer
Timer class raises Timer events at
specific intervals.
To “hear” Timer events, a class must
implement t...
6
Anonymous Classes
Defined within another class, and not
given a specific name.
Anonymous inner classes can be hidden
fro...
6
Anonymous Classes
Defined within another class, and not
given a specific name.
Anonymous inner classes can be hidden
fro...
Upcoming SlideShare
Loading in …5
×

Chapter 06

207 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
207
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Chapter 06

  1. 1. Event-Driven Programming Chapter 6
  2. 2. 6 Event Sources and Listeners An event is an object that signals something has happened. An event source is the object that raises an event. An event listener is an object responding to an event raised by an event source.
  3. 3. 6 Mouse Events Import the java.awt.event.* library Implement the interface of the MouseListener class For MouseListener the programmer must implement the methods: mouseEntered() mouseExited() mousePressed() mouseReleased() mouseClicked()
  4. 4. 6 MouseClick.java Applet responds to mouseClicked events by drawing ovals in the applet window
  5. 5. 6 Creating a Timer Timer class raises Timer events at specific intervals. To “hear” Timer events, a class must implement the ActionListener interface. ActionListener can be defined as a standard Java-named class or as an anonymous inner class.
  6. 6. 6 Anonymous Classes Defined within another class, and not given a specific name. Anonymous inner classes can be hidden from other classes in the package. These classes have access to all members of the outer class.
  7. 7. 6 Anonymous Classes Defined within another class, and not given a specific name. Anonymous inner classes can be hidden from other classes in the package. These classes have access to all members of the outer class.

×