1 / 6

Event-Driven Programming

Chapter 6. Event-Driven Programming. 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. Mouse Events.

genica
Download Presentation

Event-Driven Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6 Event-Driven Programming

  2. 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. 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. MouseClick.java • Applet responds to mouseClicked events by drawing ovals in the applet window

  5. 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. 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.

More Related