アットウィキロゴ

pro0407xx

import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;

class pro0408 extends Frame implements Runnable{

Frame f;
Thread th;
int x,y;

public static void main(String[] args){
Frame f=new pro0408();
f.setTitle("pro0408");
f.setSize(500,500);
f.setBackground(Color.yellow);
f.show();
}

pro0408() {
addWindowListener(new stopwin());
x=0;
y=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,500,500);
g.setColor(Color.red);
x=x+(int)(50*Math.random());
y=y+(int)(50*Math.random());
if (x>500)x=0;
if (y>500)y=0;
if (x<0)x=100;
if (y<0)y=100;
g.fillRect(x,y,10,10);
}

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

public void run() {
int n;
for (n=1;n<2001;n++){
repaint();
try{th.sleep(100);} catch(InterruptedException e) { }
}
}
}
最終更新:2010年09月18日 18:03