October 2004
Intermediate to advanced
336 pages
6h 27m
English
This applet plays a game of Pong using the PongTimerTask class from the previous example.
The applet class implements two interfaces:
KeyListener receives keystrokes. The user presses 'Z' to go left and 'M' to go right. (The code uses “key typed” events rather than the lower-level “key pressed” and “key released” events.)
FocusListener determines if the applet's window has the focus, so that the game can be paused when the focus is lost.
The schedule() method on the Timer class, as called here, sets up a recurring task, and takes three parameters: an implementation of the TimerTask interface, a delay in milliseconds ...
Read now
Unlock full access