【发布时间】:2015-02-09 21:17:33
【问题描述】:
我非常清楚以前很少有人问过类似的问题。我试图实施提供的解决方案 - 徒劳无功。 ...我面临的问题是一个又一个地闪烁按钮。我可以做到这一点,但是当把闪烁的顺序放在一个循环中时——一切都会中断。感谢对 Java 新手的任何帮助。附言我不允许使用线程。我现在拥有的是:
Timer colorButton = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < pcArray.length; i++) {
playSquare = pcArray[i];
System.out.println("PlaySquare " + playSquare);
if (playSquare == 1) {
if (alreadyColoredRed) {
colorBack.start();
colorButton.stop();
} else {
red.setBackground(Color.red);
alreadyColoredRed = true;
System.out.println("RED DONE");
}
} else if (playSquare == 2) {
if (alreadyColoredGreen) {
colorBack.start();
colorButton.stop();
} else {
green.setBackground(Color.green);
alreadyColoredGreen = true;
System.out.println("GREEN DONE");
}
}
}
}
});
Timer colorBack = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (int i = 0; i < pcArray.length; i++) {
playSquare = pcArray[i];
System.out.println("PlaySquare " + playSquare);
if (playSquare == 1) {
red.setBackground(Color.gray);
alreadyColoredRed = false;
System.out.println("RED PAINTED BACK");
colorBack.stop();
} else if (playSquare == 2) {
green.setBackground(Color.gray);
alreadyColoredGreen = false;
System.out.println("GREEN PAINTED BACK");
colorBack.stop();
}
}
}
});
【问题讨论】:
-
“我非常清楚非常相似的问题..” 如果您链接到它们,我们也会完全了解它们.. 这样做怎么样?
-
谢谢你,安德鲁。将尝试以这种方式弄清楚它