简体   繁体   English

我如何从另一个jframe函数打开另一个jframe,而不必等待完成函数的执行?

[英]How can i open another jframe from another jframe function without waiting to complete the execution of function?

I want to show a progress bar. 我想显示一个进度栏。 I put the code to open the JFrame containing progress bar at the beginning of the function. 我在函数的开头放置了代码以打开包含进度条的JFrame But the progress bar opens only after the complete execution of the function 但是只有在功能完全执行后,进度条才会打开

public void function(){
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new ProgressSearch().setVisible(true);
        }
    });

    instruction 1;
    instruction 2;
    instruction 3;
    instruction 4;
    instruction 5;
}

this code above only displays the progress bar after completing the function 上面的代码仅在完成功能后显示进度栏

Try adding static "progress fields" to your class. 尝试向您的班级添加静态“进度字段”。 Then just update those fields as your JFrame is created, and get their values on your code using Class.StaticField 然后只需在创建JFrame时更新这些字段,然后使用Class.StaticField在代码中获取它们的值即可。

eg, 例如,

public class MyClass {
    public static PROGRESS;
    public MyClass () {...}
    (...)
    PROGRESS = (...);
    (...)
    PROGRESS = (...);
    (...)
}

and get MyClass.PROGRESS 并获取MyClass.PROGRESS

Also, don't forget to reset PROGRESS variable after the full completion so that every time you create another JFrame from the same class you get a clean progress from 0. 另外,不要忘记在完全完成后重置PROGRESS变量,这样,每次您从同一类创建另一个JFrame时,您都可以从0获得干净的进度。

Regards, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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