Chapter 13 Examples

These pages have the complete source code and examples from Chapter 13, Events, from the Java Developer's Resource.

This chapter introduces event driven programming. This style of programming should be very familiar to Macintosh and Windows programmers. In those environments program logic doesn't flow from the top to the bottom of the program as it does in most procedural code. Rather the operating system collects events and the program responds to them. These events may be mouse clicks, key presses, network data arriving on the Ethernet port, or any of about two dozen other possibilities. The operating system looks at each event, determines what program it was intended for, and places the event in the appropriate program's event queue.

Every application in one of these environments has an event loop. This is just a while loop which loops continuously. On every pass through the loop the application retrieves the next event from its event queue and responds accordingly. For example a double click on a word may select the word.

Java applets behave similarly. However the runtime environment (i.e. the browser) provides the event loop for the applet so there's no need to write one explicitly. Rather methods in your applet respond to each kind of event you want to process. Events that occur in a Java applet are mated with the methods that handle them. You override these methods when you want to do something special when an event happens. You ignore those events you aren't interested in.

Topics covered in this chapter include

The Examples

Examples from Other Chapters
[ Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ]
Copyright 1996 Elliotte Rusty Harold
Last Modified October 3, 1996