アットウィキロゴ

java0127

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

class game0127 extends Frame implements Runnable ,MouseMotionListener{

int px,py;
int mode;

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

game0127(){

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<200){
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;
y=e.getY() ;
x=e.getX();
if(x>200)mode=1;
if(x<200)mode=2;
}


public void paint(Graphics g){
g.setColor(Color.black);
g.fillRect(100+50*px,100+50*py,50,50);
}

}
最終更新:2011年02月07日 05:45