アットウィキロゴ

java0109

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

class game0109 extends Frame implements Runnable{

Image img;
int car;
int road[]=new int[1001];


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

game0109(){

img = Toolkit.getDefaultToolkit().getImage("an.jpg");

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<1001;n++){
road[n]=0;
if(Math.random()>0.9)road[n]=1;
}

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

public void paint(Graphics g){
int m;
g.setColor(Color.yellow);
g.fillRect(100,0,600,500);
for (m=1;m<100;m++){
g.setColor(Color.black);
if(road[car+m]==1)g.fillRect(100,500-5*m,500,5);  
}
g.drawImage(img,300,300,50,50,this);
}
}
最終更新:2011年02月09日 04:04