All pastes #186965 Raw Edit

Unnamed

public java v1 · immutable
#186965 ·published 2006-09-30 17:46 UTC
rendered paste body
import java.awt.*;import java.awt.event.*;import javax.swing.*; public class simplegraphics extends JFrame{  int x=150,y=100,xdir=1,ydir=2 ;  public simplegraphics()  {//  	initial=true;    setVisible(true);    setSize(200,200);    this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);  }  public void paint(Graphics g)  {  	g.translate(0,25);//move origin down to compromise for the title bar   	g.setColor(Color.white);               //background color  	g.fillRect(0,0,getWidth(),getHeight());//background   	g.setColor(Color.white);      //clears the old ball  	g.fillOval(x,y,20,20);          	move();                       //updates the balls position        g.setColor(Color.red);        //draws a new ball  	g.fillOval(x,y,20,20);	      }  public void move()  {  	if(x<0||x>getWidth()-20)  		xdir*=-1;  	if(y<0||y>getHeight()-45)  		ydir*=-1;  	x+=xdir;  	y+=ydir;  }  public static void main(String args[])  {    simplegraphics SG = new simplegraphics();     int step=0;    while(true)    {    	if(step%500000==0)//the number 500000 doesn't matter but a smaller number will make the                          //animation, not the ball, speed up.    	{    		SG.repaint();    	}    	step++;    }  }}