My progrm is a Keno like game where you choose your numbers out of a grid of JTextFields and then you click play and the computer should randomly change the textfield colors up to 20 times.
My problem
Alright so i have a sleep thread within my four loop, the sleep thread should pause whats happening within the four loop for a second and then change the textfield color every second but instead it waits like 10 seconds and displays all the random textfields that were chosen and changed there colors all at the same time.
Here is the code
public void computerPick()
{
for(int i = 0; i < rollAmnt; i++)
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
try
{
roll = (int)(Math.random()* 79)+ 1;
Thread.sleep(100);
if(field[roll].getBackground() == Color.white)
{
field[roll].setBackground(Color.orange);
}
else if(field[roll].getBackground() == Color.green)
{
field[roll].setBackground(Color.cyan);
win++;
}
else if(field[roll].getBackground() == Color.cyan)
{
field[roll].setBackground(Color.magenta);
field[roll].setText("NICE!");
win++;
}
}
catch(InterruptedException aoe){}
}
});
}
}
please if anyone could edit this and show me what i can do to fix this i would appreciate it a ton.
