アットウィキロゴ

java0207

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

class game0207 extends Frame implements Runnable{

int car;
int right[]=new int[300];
int left[]=new int[300];


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

game0207(){


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 n,t;

for (n=1;n<300;n++){
right[n]=0;
if(Math.random()>0.5)right[n]=1;
left[n]=0;
if(Math.random()>0.5)left[n]=1;


}

car=0;
t=1;  
while(t<100){
car=car+1;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;  
}
repaint();
}

public void paint(Graphics g){
int m;
g.fillRect(300,300,50,50);
for (m=1;m<100;m++){
if(right[car+m]==1)g.fillRect(400,5*m,5,5);
if(left[car+m]==1)g.fillRect(200,5*m,5,5);
}
}

}
最終更新:2011年02月07日 04:06