To: The Summer 1998 CS 299 -Programming in Java- Class
From: Scanlan, Clifton
Date: July 09, 1998
RE: Program 6
Due Date: July 17, 1998 - Noon
Grace Date: July 17, 1998 - Noon
Points: 25



Write a Java applet to bounce 4 different colored balls inside an applet. Each ball should be positioned in a corner of the applet. An independent thread controls each ball. As the applet begins, each ball should move at a fixed rate. Upon reaching an edge of the applet, the ball should randomly change its rate and bounce off the edge at a random angle. It should NOT appear that any ball goes out of the applet.

The following are requirements that must be followed.
1. A separate ball class should be established with only private data values, no protected or public data values. The ball constructor should be passed its color and initial coordinates. (See page 496 for the meaning of the coordinates of an Oval.) The ball class should have a public method to move the ball and public methods to return the ball's coordinates. When it has reached the edge, change the differential y or x value by a random integer from 2 to 6 pixels.
2. Another class should implement Runnable and extend the Applet. This routine's init routine should create the 4 balls, the start routine should create and start the 4 threads, the stop method should stop the threads, and the paint method should draw all 4 balls. The run method should be in an infinite loop "trying" to sleep from 0 to 3 seconds (don't forget to catch the Interrupted Exception). The run method should determine which thread it is and move the appropriate ball.

If you have any questions or ambiguities, ask ME!