Skip to main content

Java Applet program to draw and move rectangle

import java.applet.Applet;
import java.awt.*;
import java.math.*;

/*<applet code="pro" height=100 width=100></applet>
  */

public class pro extends Applet implements Runnable
{
Thread t;

public void init()
{
t=new Thread(this);
t.start();
}

public void run()
{
try
{
while(true)
{
repaint();
t.sleep(1000);
}
}catch(Exception e)
{
System.out.println(e);
}
}

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

public void paint(Graphics g)
{

Dimension d=this.getSize();

g.setColor(Color.black);
g.fillRect(0,0,d.width,d.height);


double x=Math.random()*d.width;
double y=Math.random()*d.height;
g.setColor(Color.blue);
g.fillRect((int)x,(int)y,50,50);
}

}

Comments

Popular posts from this blog

unix commands