import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
class
pro extends Frame implements Runnable{
Frame f;
Thread th;
int t,px,py;
int m,n;
int x[][]=
new int[11][11];
public static void main(String[] args){
Frame f=new pro();
f.setTitle("pro");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.show();
}
pro() {
addWindowListener(new stopwin());
t=0;
px=1;
py=1;
for (m=1;m<11;m++){
for (n=1;n<11;n++){
x[m][n]=0;
}
}
th=new Thread(this);
th.start();
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
public void paint( Graphics g ) {
g.setColor(Color.yellow);
g.fillRect(0,0,700,700);
g.setColor(Color.red);
g.fillOval(50*px+
100,600-50*py,10,10);
for (m=1;m<11;m++){
for (n=1;n<11;n++){
if (x[m][n]==0)g.fillOval(50*m+100,600-50*n,5,5);
}
}
}
public void update(Graphics g) {
paint(g);
}
public void run() {
double r;
int dx,dy;
while (t<1000){
r=Math.random();
dx=0;
dy=0;
if (r>0.2)dx=1;
if (r>0.2)dy=0;
if (r>0.4)dx=-1;
if (r>0.4)dy=0;
if (r>0.6)dx=0;
if (r>0.6)dy=1;
if (r>0.8)dx=0;
if (r>0.8)dy=-1;
px=px+dx;
py=py+dy;
if (px>10)px=10;
if (px<1)px=1;
if (py>10)py=10;
if (py<1)py=1;
x[px][py]=1;
repaint();
try{th.sleep(100);} catch(InterruptedException e) { }
t=t+1;
}
}
}
最終更新:2010年10月10日 23:19