我完全知道很少有人问过之前的非常类似的问题。我试图实施提供的解决方案 - 徒劳无功。 ...我面临的问题是闪烁按钮ONE AFTER ANOTHER。我可以做一个,但是当把闪烁的顺序放在一个循环中时 - 一切都会中断。任何帮助到Java的新人表示赞赏。附:我不允许使用线程。什么我现在有是:java Swing timer一个接一个地执行几项任务
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();
}
}
}
});
为了更好地帮助越早,张贴[MCVE](http://stackoverflow.com/help/mcve)(最小完备可验证实施例)或[SSCCE](HTTP:// WWW .sscce.org /)(简短,独立,正确的例子)。 – 2015-02-09 21:38:35
*“我完全意识到非常相似的问题..”*如果你与他们联系起来,我们也会完全意识到他们。那么做怎么样? – 2015-02-09 21:40:30
谢谢你,安德鲁。将试图找出这种方式 – KTM950 2015-02-09 21:59:42