【发布时间】:2015-01-06 15:32:39
【问题描述】:
当给定像素为白色时,机器人的行为与预期一致。但是当我用不同的颜色测试它然后变成白色时,它仍然卡在循环中:
(...)
stuck in while->else
false
(...)
可能是什么问题?代码如下:
public class test {
public static boolean ifFinished = false;
public static void main(String[] args) throws AWTException, IOException,
InterruptedException {
// Create a Robot object
Robot myRobot = new Robot();
// pick a color of given pixels
Color color = myRobot.getPixelColor(912, 487);
System.out.println("Red color of pixel = " + color.getRed());
System.out.println("Green color of pixel = " + color.getGreen());
System.out.println("Blue color of pixel = " + color.getBlue());
while (ifFinished == false) {
//Checks if color is white
if (color.getRed() == 255 && color.getGreen() == 255
&& color.getBlue() == 255) {
ifFinished = true; //if it is set ifFinished to true
System.out.println("stuck in while->if");
} else
Thread.sleep(1000);
ifFinished = false;
System.out.println("stuck in while->else");
System.out.println(ifFinished);
}
}
}
【问题讨论】: