import java.awt.*;
import java.awt.event.*;
class game1110 extends Frame implements Runnable ,MouseListener,MouseMotionListener{
int px,py;
int mode;
public static void main(String [] args) {
Frame f=new game1110();
f.setTitle("game1110");
f.setSize(700,700);
f.setBackground(Color.yellow);
f.setVisible(true);
}
game1110(){
addMouseListener(this);
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=200;
py=100;
t=0;
while(t<500){
if(px>500)px=500;
if(px<100)px=100;
repaint();
try{
Thread.sleep(50);
}catch(InterruptedException e){}
t=t+1;
}
repaint();
}
public void mouseEntered(MouseEvent e){
}
public void mouseExited(MouseEvent e){
}
public void mousePressed(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
public void mouseClicked(MouseEvent e){
py=py+10;;
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
int x,y;
y=e.getY() ;
x=e.getX();
if(x>px+10)px=px+10;
if(x<px-10)px=px-10;
}
public void paint(Graphics g){
g.setColor(Color.black);
g.fillRect(px,py,50,50);
}
}
最終更新:2011年02月11日 22:33