I have a problem with a function I have made for a Whack a mole game in java fx.
In the function, I am trying to change the image of 1 to 3 buttons. The problem is that I am trying to set a delay between each image change. I tryed the Wait() function but it gives me a java.lang.IllegalMonitorStateExceptionstrong
Exception
The function ChangeImageActive
changes the image of a button to tell to the player that he needs to hit the button.
public void ActivateRandomButtons(ArrayList<MSButtons> btnList)
{
try
{
int n;
int numberOfButtons = rand.nextInt(3);
for (int i = 0; i < numberOfButtons; i++)
{
n = rand.nextInt(9);
btnList.get(n).ChangeImageActive();
// Wait 1 second before resuming for loop
wait(1000);
}
}
catch (java.lang.Exception e)
{
System.out.print(e.getMessage().toString());
}
}
I can show more of my code if needed. Thanks