import java.awt.*;
import java.awt.event.*;
class game0210 extends Frame implements Runnable,MouseMotionListener{
int t;
int gun;
int dg;
public static void main(String [] args) {
Frame f=new game0210();
f.setTitle("game0210");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0210(){
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;
while(t<200){
gun=gun+dg;
if (gun>10)gun=10;
if(gun<1)gun=1;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public void paint(Graphics g){
g.fillRect(100+50*gun,600,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:46