I have a JPanel class which starts another thread using "implements runnable". This other thread will then at various points call a method in the JPanel class which on doing so will then need to wait for the user input. I have attempted to implement it like this:
Method in JPanel class called by other thread that needs to wait:
public void methodToWait()
{
while(conditionIsMet)
{
try
{
wait();
}
catch
{
e.printStackTrace();
}
}
}
Method in JPanel class that notifies on wait on user input:
public void mouseClicked(MouseEvent event)
{
notifyAll();
}
However, upon running the application it throws a "java.lang.IllegalMonitorStateException" upon calling the wait, why is it doing this and how do I resolve the issue?