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

public class paddlegame extends Applet implements Runnable
{



	Image imgBuffer;
	Graphics gBuffer;
	paddle p;
	field f;
	ball b;
	Thread runner = null;

	public paddlegame()
	{
	}

	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 
		
	   	p.draw();
		b.draw();
 		//f.draw();

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

	public String getAppletInfo()
	{
		return "Name: paddlegame\r\n" +
		       "Author: Unknown\r\n" +
		       "Created with Microsoft Visual J++ Version 1.0";
	}


	public void init()
	{

        resize(320, 240);
		imgBuffer = createImage (this.size().width, this.size().height);
		gBuffer = imgBuffer.getGraphics();
		gBuffer.setColor(Color.white);
		gBuffer.fillRect(0,0,this.size().width, this.size().height);
 		gBuffer.setColor(Color.black);
		p = new paddle(310, 100);
		b = new ball(30, 30, 10);
		f = new field(0, 0, 320, 240);

		p.setGraphics(gBuffer);
		b.setGraphics(gBuffer);
		f.setGraphics(gBuffer);

		b.setPaddle(p);
		b.setApplet(this);
 		f.draw();
		p.draw();
		b.draw();

	}

	public void destroy()
	{
	}

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


	public boolean mouseMove (Event e, int x, int y)
	{
		p.move(y);
		return false;
	}



}
