View Single Post
  #2 (permalink)  
Old 06-28-2009, 08:21 PM
Fubarable's Avatar
Fubarable Fubarable is offline
Moderator
 
Join Date: Jun 2008
Posts: 6,506
Rep Power: 8
Fubarable is on a distinguished road
Default
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

Last edited by Fubarable; 06-28-2009 at 08:25 PM.
Reply With Quote