/**
 * @(#)Bounce.java
 *
 * Sample Applet application
 *
 * @author 
 * @version 1.00 05/07/26
 */
 
import java.awt.*;
import java.applet.*;
import java.util.*;

public class Bounce extends Applet
{		
	// declare some variables
	double	timestep = 0.1; // number of seconds between frames
	double	x = 290.0;
	double	y = 250.0;
	double	dx = 40.0; // number of pixels moved (in x) in a second
	double	dy = 80.0; // number of pixels moved (in y) in a second
	
	// update the frame
	public void animate()
	{
		// TODO: every frame, change the x and y position of the ball based on its velocity (dx and dy)
		
		// TODO: if the ball hits a wall, reposition the ball (as though it bounced) and change the velocity accordingly
	}
	
	// draw the frame
	public void paint(Graphics g)
	{
		animate();
		
		// draw the edges
		g.setColor(Color.blue);
		// TODO: draw the top, bottom, left, and right edges making a 20 pixel border around the whole applet
		
		// draw the ball
		g.setColor(Color.orange);
		// TODO: draw the ball centered around the position x,y with a radius of 10
		
		// draw the velocity
		g.setColor(Color.red);
		// TODO: draw a line indicating the velocity of the ball (eg from (x,y) to (x+dx, y+dy) )
	}
	
	// The code below here is used to set up the animation timer.
	Animation a;
	class Animation extends TimerTask
	{
		Timer time = null;
		Bounce applet = null;
		
		public Animation(Bounce app)
		{
			applet = app;
		}
		public void start()
		{
			time = new Timer();
			time.schedule(this, 100, (int)(1000.0*timestep));
		}
		public void stop()
		{
			time.cancel();
		}
		public void run()
		{
			applet.repaint();
		}
	}
	public void start()
	{
		a.start();
	}
	public void stop()
	{
		a.stop();
	}
	public void init()
	{
		a = new Animation(this);
	}
}
