GUI Freezing when wait()'ing for an actionEvent

Posted on 2006-03-24
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
Question by:Savag3
    LVL 23

    Expert Comment

    public class KwartoClient implements ActionListener,Runnable

    just try implmenting Runnable class instead of Extending Thread class
    LVL 1

    Author Comment

    that didn't change anything
    LVL 14

    Accepted Solution

    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.
    LVL 14

    Expert Comment

    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.
    LVL 11

    Expert Comment

    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.
    LVL 10

    Expert Comment

    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.

    LVL 1

    Author Comment

    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.
    LVL 86

    Expert Comment

    Something odd here:


    actionPerformed(ActionEvent ev) {






     public synchronized void setMove(int move) {

         this.move= move;

         madeMove = true;



    What happened to the parameter?

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now