アットウィキロゴ

game04 p

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

class game04 extends Frame implements Runnable{

int t;
int gun;
int dg;

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

game04(){


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;
if (gun<1)gun=1;
if (gun>10)gun=10;

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月28日 22:15