Play the Game Pong, Part II

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

Get Find the Bug A Book of Incorrect Programs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.