アットウィキロゴ

pro0406

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

class pro0406 extends Frame implements Runnable{

Frame f;
Thread th;
int x,y;

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

pro0406() {
addWindowListener(new stopwin());
x=100;
y=100;
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+50;
y=y+50;
if (x>500)x=0;
if (y>500)y=0;
g.fillRect(x,y,10,10);
}

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

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