アットウィキロゴ

java0110

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

class game0110 extends Frame implements Runnable,MouseMotionListener{

int t;
int gun;
int dg;
int ufo;


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

game0110(){

addMouseMotionListener(this);

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;
ufo=20;
while(t<200){
gun=gun+dg;
ufo=ufo-1;
if (ufo<0)ufo=20;
if (gun>10)gun=10;
if(gun<1)gun=1;
repaint();
try{
Thread.sleep(200);
}catch(InterruptedException e){}
t=t+1;    
}
repaint();
}


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

}

public void mouseDragged(MouseEvent e) {
    }

public void mouseMoved(MouseEvent e) {
int x;  
x=e.getX();
if (x>50*gun+150)dg=1;
if (x<100+50*gun-50)dg=-1;
}



}
最終更新:2011年02月09日 19:57