当前位置: 技术问答>java相关
哥們兒, 怎麼取得鼠標的位置
来源: 互联网 发布时间:2015-10-04
本文导语: 那位兄弟知道, 我怎麼才能得到鼠標在顯示屏慕上的座標位置, 謝了! | import java.awt.*; import java.awt.event.*; public class Example18_6 extends Applet implements MouseMotionListener { TextField text; public void...
那位兄弟知道, 我怎麼才能得到鼠標在顯示屏慕上的座標位置, 謝了!
|
import java.awt.*;
import java.awt.event.*;
public class Example18_6 extends Applet implements MouseMotionListener
{ TextField text;
public void init()
{ text=new TextField();
setLayout(new BorderLayout());
setBackground(Color.green);
addMouseMotionListener(this); add(text,"South");
}
public void mouseDragged(MouseEvent e)
{text.setBackground(Color.red);
text.setText("鼠标的坐标:"+"("+e.getX()+","+e.getY()+")");
}
public void mouseMoved(MouseEvent e)
{text.setBackground(Color.blue);
text.setText("鼠标的坐标:"+"("+e.getX()+","+e.getY()+")");
}
}
import java.awt.event.*;
public class Example18_6 extends Applet implements MouseMotionListener
{ TextField text;
public void init()
{ text=new TextField();
setLayout(new BorderLayout());
setBackground(Color.green);
addMouseMotionListener(this); add(text,"South");
}
public void mouseDragged(MouseEvent e)
{text.setBackground(Color.red);
text.setText("鼠标的坐标:"+"("+e.getX()+","+e.getY()+")");
}
public void mouseMoved(MouseEvent e)
{text.setBackground(Color.blue);
text.setText("鼠标的坐标:"+"("+e.getX()+","+e.getY()+")");
}
}