アットウィキロゴ

animeno kihon

import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
class pro extends Frame implements Runnable{

Frame f;
Thread th;
int t,x,y;

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;
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,700,700);
g.setColor(Color.red);
g.fillOval(x+100,y+100,10,10);
}

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

public void run() {
while (t<1000){
x=x+(int)(50*Math.random())-25;
y=y+(int)(30*Math.random())-15;
if (x>500)x=0;
if (y>500)y=0;
if (x<0)x=100;
if (y<0)y=100;
repaint();
try{th.sleep(100);} catch(InterruptedException e) { }
t=t+1;
}
}

}
最終更新:2010年10月10日 22:45