
308 CHAPTER 6 Flow of Control,Part 2: Looping
Using the clearRect method, we can erase the whole applet window by treat-
ing it as a rectangle whose (x, y) coordinate is the upper-left corner (0, 0)
and whose width and height are the same as the applet window. We’ve
already seen that we can get the width of the window by calling the
getWidth method. As you might suspect, we can get the height of the applet
window by calling the getHeight method. Note that after we call clearRect,
the applet window will be empty; however, we draw the next ball so quickly
that the user doesn’t see the ball being erased.
Here’s the pseudocode for the animation:
set starting ...