import java.awt.*;
import java.awt.Graphics;
import java.awt.event.*;
class pro0422 extends Frame implements Runnable{
Frame f;
Thread th;
int t;
int gun;
public static void main(String[] args){
Frame f=new pro0422();
f.setTitle("
pro0422");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.show();
}
pro0422() {
addWindowListener(
new stopwin());
t=0;
gun=5;
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.fillRect(
100+50*gun+10,590,10,10);
g.fillRect(100+50*gun,600,30,10);
}
public void update(Graphics g) {
paint(g);
}
public void run() {
int dg;
while (t<100){
dg=1;
if (Math.random()>0.5)dg=-1;
gun=gun+dg;
if (gun>10)gun=10;
if (gun<1)gun=1;
repaint();
try{th.sleep(100);} catch(InterruptedException e) { }
t=t+1;
}
}
}
最終更新:2010年09月20日 23:52