
/* 
   This applet shows a red ball bounding around on a black backgound.
   It is based on the animation framework from SimpleAnimationApplet.java.
   It also requires the class BoundingBall, which is defined in the
   file BouncingBall.java.
   
   David Eck, 10 October 1998
*/


import java.awt.*;

public class BouncingBallsApplet extends SimpleAnimationApplet {


   BouncingBall redBall;  // The red ball.


   public void init() {
          // This routine is called by the system when the applet if
          // first created.  In this applet, it creates the red ball
          // and calls setMillisecondsPerFrame to set the speed of the
          // animation.

      int w = getSize().width;  // Applet width, to be used for positioning the ball.
      int h = getSize().height; // Applet height, to be used for positioning the ball.

      redBall = new BouncingBall(Color.red, w/2, h/2, 16);

      setMillisecondsPerFrame(50);  // This routine is defined in SimpleAnimationApplet.
                                    // It says that I want each frame to take 50
                                    // milliseconds (1/20 second).  This is about
                                    // twice as fast as the default rate.  (Note that
                                    // there is no guarantee that the computer can
                                    // actally draw frames at the rate you request.)
   } // end init()
   
   
   public void drawFrame(Graphics g, int width, int height) {
          // This routine is called by the animation framework every time
          // a new frame needs to be drawn.  For this animation, this
          // routine draws a black background, then calls the ball's
          // doFrame method, which draws the ball and updates its state
          // for the next frame.

      g.setColor(Color.black);          // Fill the applet with a black background.
      g.fillRect(0,0,width,height);

      redBall.doFrame(g,width,height);

   } // end drawFrame()
      

} // end class BouncingBallsApplet