The javax.swing.Timer API has a method that prevents it from looping more than once. I can't remember the name of the method (something like setRepeating(false)), but if you look it up, you'll find it.
To set a button back to it's normal background, I believe that setBackground(null) may work. I'm not at my computer with a java compiler but rather am at work, so I can't test this.
This needs to be called from within the Timer ActionListener's actionPerformed method.
edit: the Timer method is setRepeats(false):
|
Code:
|
one.setBackground(Color.red);
seconds = 0;
int delay = 1000; //milliseconds
Timer timer = new Timer(delay, taskPerformer);
timer.setRepeats(false);
timer.start();
// one.setBackground(null); this must be called in actionPerformed |