I am new to this forum and Java, so this is my first post.
I have some gray JButtons and, when clicked, I want them to turn red for 500 milliseconds and then blue. I put an action listener on them and handled the event with Thread.sleep(500) between filling red and filling blue, and even a repaint() between those (to the panel where the buttons are displayed), but apparently the thread that does the repaints is postponed until after the thread that sleeps. It seems like there should be a simple solution, but I cannot think of one. What I have tried is this (and it just draws the buttons pressed as blue):
[code = Java]
private boolean handleControl(JButton buttonPressed)
{
buttonPressed.setBackground(Color.RED);
gui.repaint();
try
{
Thread.sleep(500);
}
catch(InterruptedException e)
{
}
buttonPressed.setBackground(Color.BLUE);
return true;
}
[/code]
My question is, can this be done in a simple way, or do I have to create my own thread and put everything on it?