アットウィキロゴ

がめ01

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

class game01 extends Frame implements Runnable{

int t;
int gun;
int dg;

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

game01(){


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(){

t=1;
dg=1;
gun=5;
while(t<500){
dg=1;
if (Math.random()>0.5)dg=-1;
gun=gun+dg;

repaint();
try{
Thread.sleep(500);
}catch(InterruptedException e){}
t=t+1;
}

}


public void paint(Graphics g){
g.fillRect(100+50*gun,600,50,50);
}

}
最終更新:2011年01月27日 17:01