アットウィキロゴ

がめ1211

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

class game1211 extends Frame implements Runnable{

int horse;
int t;
int stage;

public static void main(String [] args) {
       Frame f=new game1211();
       f.setTitle("game1211");
       f.setSize(700,700);
       f.setBackground(Color.yellow);
       f.setVisible(true);
   }

game1211(){

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;
horse=0;
while(t<500){
d=(int)(10*Math.random());
horse=horse+d;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;  
if(horse>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(350,600-horse,50,50);  
}

if(stage==2){  
g.drawString("完走",200,500);  

}

}
}
最終更新:2011年02月10日 19:07