我想让鼠标点击开始一个循环,报告鼠标的位置,直到点击鼠标。我开始循环并报告位置没有问题,但是即使鼠标单击两次鼠标单击方法结束循环,或者应该,程序无限继续循环。
public JFramethingy() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.addMouseListener(new MouseAdapter() {
int numClicked;
public void mouseClicked(MouseEvent arg0) {
numClicked++;
for (int i = 0; i > -1;) {
if(i % 1002000 == 0){
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int x = (int) b.getX();
int y = (int) b.getY();
System.out.println(x + "," + y);
}
if (numClicked > 1){
numClicked = 0;
i = -3;
}
i++;
}
}
});