所以这是我正在使用的整个文件,无奈之下,我在每个事件中都定义了 x 和 y,但我仍然一无所获。这是一个多类项目,我应该在哪里做addMouseListener()
?为什么这不能引起事件?(注意:坐标的打印run()
工作。)这是一个小程序项目,小程序工作正常,只是没有注册这个事件。
public class ClickCheck implements Runnable, java.awt.event.MouseListener {
public int x, y;
public ClickCheck() {
Thread t = new Thread(this);
t.start();
}
public void mouseClicked(java.awt.event.MouseEvent ev) {
x = ev.getX();
y = ev.getY();
System.out.println(x + "," + y);
}
public void mousePressed(java.awt.event.MouseEvent ev) {
x = ev.getX();
y = ev.getY();
System.out.println(x + "," + y);
}
public void mouseReleased(java.awt.event.MouseEvent ev) {
x = ev.getX();
y = ev.getY();
System.out.println(x + "," + y);
}
public void mouseEntered(java.awt.event.MouseEvent ev) {
x = ev.getX();
y = ev.getY();
System.out.println(x + "," + y);
}
public void mouseExited(java.awt.event.MouseEvent ev) {
x = ev.getX();
y = ev.getY();
System.out.println(x + "," + y);
}
public void run() {
System.out.println(x + "," + y);
}
}