Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Make thread wait for JFrame close?

I've tried this

In main method
field - static InitThread init = new InitThread();
Code
init.start();
        synchronized (init) {
            init.wait();
            System.out.println("fin");
        }

InitThread
Code
public class InitThread extends Thread {

    @Override
    public void run() {
        synchronized (this) {
            if (settings.get("user_info", "username", String.class) == null || settings.get("user_info", "password", String.class).equals("")) {
                new LoginForm(this);
            } else {
                System.out.println("x");
                notify();
            }
        }
    }
}

But it writes "fin" before "x"
There's a button on the LoginForm that calls notify() on InitThread too

Edit: removed InitThread from the constructor of LoginForm since it's static and I can just access it from main class

Edit2: Forget this, just gonna make it run the code I want it to wait for inside the interface :/
[Image: apgoRtH.png]
You can add a shutdown hook to your program and if you set the default close operation to 3 (exit JVM on close) it will execute the hook before the JVM exits completely


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by bytespmApr 5, 2025 08:33 AM 10 445 Apr 5, 2025 08:33 AM
Last Post: Robert Rouge
[C#] by passwordsApr 19, 2018 07:30 PM 2 167 Apr 19, 2018 07:30 PM
Last Post: gigajew
[Java] by LosesApr 27, 2017 01:50 PM 0 158 Apr 27, 2017 01:50 PM
Last Post: Loses