We help IT Professionals succeed at work.

GUI Freezing when wait()'ing for an actionEvent

Savag3 asked
Medium Priority
Last Modified: 2012-05-05
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
Watch Question

Siva Prasanna KumarPrincipal Solutions Architect
Top Expert 2006

public class KwartoClient implements ActionListener,Runnable

just try implmenting Runnable class instead of Extending Thread class


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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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.



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.
Top Expert 2016

Something odd here:


actionPerformed(ActionEvent ev) {






 public synchronized void setMove(int move) {

     this.move= move;

     madeMove = true;



What happened to the parameter?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.