
/**
 *  This applet shows a red ball bouncing around within
 *  the limits of an applet.  It uses a MovingBall object
 *  to represent the ball.
 */


import java.awt.*;

public class Balls extends SimpleAnimationApplet {

   private MovingBall ball;  // The bouncing ball.


   /**
    *  The init() method is called automatically by the system
    *  when the applet is first created.  Its function is to 
    *  initialize the applet.  In this case, I create the
    *  MovingBall applet and adjust the animation timing.
    */
   public void init() {
   
      // Create the MovingBall object.  The x- and y-limits on its
      // motion are chosen so that it roams around in the entire
      // applet (getSize().width represents the width of the applet,
      // and getSize().height represents its height).  The radius
      // of the ball is set to 10, rather than the default 5, but
      // the default red color is not changed.

      ball = new MovingBall( 0, getSize().width, 0, getSize().height );
      ball.setRadius(10);
      
      // Set the desired time per frame to be 33 milliseconds, which
      // means that there will be about 30 frames per second.
      
      setMillisecondsPerFrame(33);
      
   } // end init()
   

   /**
    *  The drawFrame method is called each time a frame of the animation
    *  needs to be drawn.  In this case, the frame is filled with a 
    *  light blue background color.  Then the moving ball is drawn,
    *  after calling its travel() method to make it move from one frame
    *  to the next.
    */
   public void drawFrame(Graphics g) {
   
      int width, height;  // The size of the applet.
      width = getSize().width;
      height = getSize().height;
      
      // Draw a light blue background with a darker blue border.
      
      g.setColor( new Color(180,180,255) );
      g.fillRect( 0, 0, width, height );
      g.setColor( Color.blue );
      g.drawRect( 0, 0, getSize().width - 1, getSize().height - 1 );
      
      // Move the ball by calling its travel() method, then draw it.
      // Calling the travel() method once in each frame is what makes
      // the ball move.
      
      ball.travel();
      ball.draw(g);
      
   } // end drawFrame()
   

} // end class Balls
