import java.awt.*;
import java.awt.event.*;
class game0125 extends Frame implements Runnable ,MouseMotionListener{
int px,py;
int mode;
public static void main(String [] args) {
Frame f=new game0125();
f.setTitle("game0125");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game0125(){
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(){
int t;
mode=1;
px=1;
py=1;
t=0;
while(t<500){
if(mode==1)px=px+1;
if(mode==2)px=px-1;
repaint();
try{
Thread.sleep(100);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
int x,y;
int h;
y=e.getY() ;
x=e.getX();
mode=3;
h=0;
if(x>350)h=h+1;
if(y>500)h=h+1;
if(h==2)mode=1;
h=0;
if(x<350)h=h+1;
if(y>500)h=h+1;
if(h==2)mode=2;
}
public void paint(Graphics g){
g.setColor(Color.red);
g.fillRect(0,500,350,200);
g.setColor(Color.green);
g.fillRect(350,500,350,200);
g.setColor(Color.black);
g.fillRect(100+50*px,100+50*py,50,50);
}
}
最終更新:2011年02月07日 06:09