import java.awt.*;
import java.awt.event.*;
class game1212 extends Frame implements Runnable{
int horse1,horse2;
int t;
int stage;
public static void main(String [] args) {
Frame f=new game1212();
f.setTitle("game1212");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game1212(){
Thread th=new Thread(this);
th.start();
addWindowListener(new stopwin());
}
class stopwin extends WindowAdapter{
public void windowClosing(WindowEvent we){System.exit(0);}
}
public void run(){
int d;
stage=1;
t=1;
horse1=0;
horse2=0;
while(t<500){
d=(int)(10*Math.random());
horse1=horse1+d;
d=(int)(10*Math.random());
horse2=horse2+d;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
if(horse1>500)t=1000;
if(horse2>500)t=1000;
}
stage=2;
repaint();
}
public void paint(Graphics g){
if(stage==1){
g.setColor(Color.black);
g.fillRect(100,100,500,500);
g.setColor(Color.red);
g.fillRect(200,600-horse1,50,50);
g.fillRect(400,600-horse2,50,50);
}
if(stage==2){
if(horse1>500)g.drawString("1",200,500);
if(horse2>500)g.drawString("2",200,500);
}
}
}
最終更新:2011年02月10日 19:35