【发布时间】:2017-06-04 12:25:51
【问题描述】:
我正在尝试编写一个检测“空闲”状态的程序,但我的代码中没有发现问题。有人可以帮我一个有用的提示吗?这是我的代码:
package idlestatus;
import java.awt.MouseInfo;
public class Idlestatus {
public static void main(String[] args) throws InterruptedException {
Integer firstPointX = MouseInfo.getPointerInfo().getLocation().x;
Integer firstPointY = MouseInfo.getPointerInfo().getLocation().y;
Integer afterPointX;
Integer afterPointY;
while (true) {
Thread.sleep(10000);
afterPointX = MouseInfo.getPointerInfo().getLocation().x;
afterPointY = MouseInfo.getPointerInfo().getLocation().y;
if (firstPointX == afterPointX && firstPointY == afterPointY) {
System.out.println("Idle status");
} else {
System.out.println("(" + firstPointX + ", " + firstPointY + ")");
}
firstPointX = afterPointX;
firstPointY = afterPointY;
}
}
}
【问题讨论】:
-
或使用
int而不是Integer。 -
好吧...它解决了,谢谢先生!
标签: java if-statement mouseover