
import java.applet.*;
import java.awt.*;

public class backandforth extends Applet implements Runnable
{



	Image imgBuffer;
	Graphics gBuffer;

	ball2 b;
	public  int fieldwidth = 1024;//default
	public  int fieldheight = 60;
	Thread runner = null;


 

	public void update(Graphics g) 
	{
		paint(g);
	}

	public void start() 
	{
		if(runner == null)
		{
		runner = new Thread(this);
		runner.start();
		}
	}
   
   public void stop()
   {
      if (runner != null)
      {
         runner.stop();
         runner = null;
      }
   }

   public void run() 
	{

	while (runner != null) 
	{
		//move ball and paddle here 
		

		b.draw();
 		//f.draw();

		try {Thread.sleep(30);} catch (InterruptedException e){}
		repaint();
		}
		runner = null;
	}
 



	public void init()
	{

		//old way -- resize applet to fixed size
        	//resize(fieldwidth, fieldheight);

		//if you want to handle dynamic resizing, you'll have to handle the
		//double buffer differently. Now, it works well if you decrease size,
		//but doesn't handle an increase. 
		String param = getParameter("ballsize");
		int ballsize = Integer.parseInt(param);
		param = getParameter("xinc");
		int xinc = Integer.parseInt(param);
		param = getParameter("ballr");
		int ballr = Integer.parseInt(param);
		param = getParameter("ballg");
		int ballg = Integer.parseInt(param);
		param = getParameter("ballb");
		int ballb = Integer.parseInt(param);
		Color ballcolor = new Color(ballr, ballg, ballb);

		param = getParameter("backr");
		int backr = Integer.parseInt(param);
		param = getParameter("backg");
		int backg = Integer.parseInt(param);
		param = getParameter("backb");
		int backb = Integer.parseInt(param);
		Color backcolor = new Color(backr, backg, backb);

		param = getParameter("randomcolors");
		boolean randomcolors = Boolean.valueOf(param).booleanValue();

		param = getParameter("overlay");
		boolean overlay = Boolean.valueOf(param).booleanValue();

		imgBuffer = createImage (this.getSize().width, this.getSize().height);
		gBuffer = imgBuffer.getGraphics();
		gBuffer.setColor(backcolor);
		gBuffer.fillRect(0,0,this.getSize().width, this.getSize().height);
 		//gBuffer.setColor(Color.black);

		b = new ball2(30, 30, ballsize, xinc, backcolor, ballcolor, randomcolors, overlay);
		b.setGraphics(gBuffer);

		b.setBackandforth(this);
		b.draw();

	}



	public void paint(Graphics g)
	{
		g.drawImage(imgBuffer, 0, 0, this);
	}






}
