Re: Need time waster code or something.
Ok, this is me from another account.
I had something like that, Audrey, and it works, but switched it to a
timer to try to solve my current problem.
NOW, I need to flash some buttons in succession, and not overlap each
other.
Here's my code for flashing the button:
public void flashButton()
{
buttonFlash bf = new buttonFlash();
}
public class buttonFlash
{
Toolkit toolkit;
Timer timer;
public buttonFlash()
{
toolkit = Toolkit.getDefaultToolkit();
timer = new Timer();
//button.setIcon(onIcon);
timer.schedule(new RemindTask(), 250, 250);
button.setIcon(offIcon);
}
class RemindTask extends TimerTask
{
public void run()
{
button.setIcon(onIcon);
System.exit(0); //Stops the AWT thread
//(and everything else).
}
}
}
Here's the code for calling button flashes in succession:
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == exitButton)
{
System.exit(0);
}
else if (source == runButton)
{
// reset values and counter
blueButton.resetGame();
blueButton.flashButton();
try
{
Thread.sleep(250);
}
catch (InterruptedException ie) {}
redButton.flashButton();
greenButton.flashButton();
yellowButton.flashButton();
}
else if (source == validateButton)
{
//check answers against generated values
}
}
The code between the blueButton and the redButton does not do the job.
In fact, most of the time, I can't see the blueButton flash, but it
does sometimes, and partially other times, so I know its going off.
So, how do I put a lag between these flashButton calls?