6
Event-Driven Programming Chapter 6

Chapter 06

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Chapter 06

Event-Driven Programming

Chapter 6

Page 2: Chapter 06

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.

Page 3: Chapter 06

6

Mouse EventsImport the java.awt.event.* libraryImplement the interface of the MouseListener classFor MouseListener the programmer must implement the methods:

mouseEntered()mouseExited()mousePressed()mouseReleased()mouseClicked()

Page 4: Chapter 06

6

MouseClick.javaApplet responds to mouseClicked events by drawing ovals in the applet window

Page 5: Chapter 06

6

Creating a TimerTimer 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.

Page 6: Chapter 06

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.