GUI Freezing when wait()'ing for an actionEvent

Can someone explain why the GUI freezes when running this code?

I really don't understand. The GUI should run in a seperate thread, and fire events
while the other thread is waiting for them. But since the GUI freezes, nothing happens.

This is a really basic version of what I'm trying to do in my program.

Since this is really urgent I'm awarding 300 points.

Thanks in advance,
Tjeerd Beorman
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
public class KwartoClient implements ActionListener,Runnable

just try implmenting Runnable class instead of Extending Thread class
Savag3Author Commented:
that didn't change anything
check what happens if You change the line




inside a while loop. If that solves the freezed GUI, then You'll have to do it in other way.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Also can You post the code which can be compiled, but with most of the code removed. Even doing that may show You where the real problem is.
In your loop:

while (!madeMove ) {

I don't see how the madeMove boolean is going to get changed.

Is there something going on in another thread to set the madeMove to true? If so, are you issuing a notify() or notifyAll() after you set the boolean to true? I'm guessing the wait is hanging until it receives a notify or interrupt.
One hint here. If you invoke wait on a certain instance XYZ of an object, you *must*
invoke notify or notifyAll on the *same* instance, XYZ of that object. Otherwise, your
thread will wait indefinitely.

It's better to use a wait with a timeout wait(milliseconds) for handling such situations.
In case if your second thread fails to notify the first thread, your code shouldn't hang.

Savag3Author Commented:
Okay I think I found the problem:

The game was actually initiated in a GUI class (GameOptions) on pressing of the OK Button. So the game actually
ran inside a function inside a function of that GUI class.

Let me try to initiate the game loop differently.
Something odd here:


actionPerformed(ActionEvent ev) {






 public synchronized void setMove(int move) {

     this.move= move;

     madeMove = true;



What happened to the parameter?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.