index (461)


Chapter 13: Events 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 life cycle of a Java applet including the init, start, stop and destroy methods The paint, repaint, and update methods and the difference between them Input from the keyboard Special keys Input from the mouse The structure of Event Objects The handleEvent method The Examples Example 13.1: Life Cycle Example 13.2: Event Tutor Example 13.3: The Typewriter Applet Example 13.4: Printing All Events with the handleEvent method Examples from Other Chapters [ Cafe Au Lait | Books | Trade Shows | Links | FAQ | Tutorial | User Groups ] Copyright 1996 Elliotte Rusty Harold elharo@sunsite.unc.edu Last Modified October 3, 1996

Wyszukiwarka

Podobne podstrony:
index
index
index
index
index
index
index
index

więcej podobnych podstron