All pastes #77405 Raw Edit

wegstar

public text v1 · immutable
·published 2006-07-03 00:07 UTC
rendered paste body
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
import java.awt.Graphics;
public class Pong extends Applet implements KeyListener
{
     Frame frame = new Frame();
     Graphics screen;  // this would be drawn to the screen
     
     Image buffer; // the buffer
     
     
	 Dimension dim;
     
	 int pX = 0, pY = 0;
	 int speed = 3;
	 boolean done = true;

     public void init() 
     {
          
          dim = getSize(); //get width and height of applet
          
     
          setBackground(Color.black);
          
          buffer = createImage(dim.width,dim.height);
          
          screen = buffer.getGraphics(); // link buffer with screen
     }

      public void paint(Graphics g) 
     {
          
          screen.clearRect(0,0,dim.width,dim.width); // clear it...
          //screen.setColor(Color.red);
          //screen.drawString("Bad Double-buffered",10,10);
          
         screen.fillRect(pX,pY,10,30);
          
          this.getGraphics().drawImage(screen,0,0,this);
     }

     // no wiping, just draw buffer onto screen
     public void update(Graphics g)
     {
          paint(g);
     }
	public void keyReleased(KeyEvent e)
	{
	}
	public void keyTyped(KeyEvent e)
	{
	}
	public void keyPressed(KeyEvent e)
	{
		//manage the keys
		int id = e.getKeyCode(); // get key code
	
		if(id == KeyEvent.VK_KP_UP){
			if((pY+30) < 300)
				pY += speed;
			if((pY + 30) > 300)
				pY = 270;
		}
		else if(id == KeyEvent.VK_KP_DOWN)
		{
			if(pY > 0 )
				pY -= speed;
			if(pY < 0 )
				pY = 0;
		
		}
	
	}
	
	public void gameLoop()
	{
	
	while(!done){
	

	
	}
	
	}
 
     

 }