简体   繁体   中英

Creating JFrame in a new Thread(new messageloog)

Hi i am trying to create multi JFrames but I want each one to has its own Thread (message loop) ,so when one JFrame freezes the others will keep working

i tried to create each jframe from different Threads, but they are still working in the "AWT-EventQueue-0" thread.

i come from a dotnet background. so when i want to do this scenario in a winForms app i usually call Application.run(new form()) from a new thread

can u please tell me how to do this in java ?

thanks in advance!

There is only UI thread in Java, no matter how many frames you open. I would suggest you to execute the long running operation within a thread.

public void actionPerformed(ActionEvent e)
{
    new Thread(new FrameRunnable()).start();
}

public class FrameRunnable implements Runnable
{
    public void run()
    {
        // Do stuff here
    }
}

Hope this will help.

Read the section from the Swing tutorial on Concurrency to understand how the Event Dispatch Thread works. All updates to GUI components must be done on the EDT. If you have long running tasks, you can use a SwingWorker or a separate Thread along with SwingUtilities.invoke(...) later to add code to the EDT.

Create a new thread for each JFrame generated. Take note of your Thread variables and pass it around on your Runnable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM