简体   繁体   English

使JavaFX应用程序变为非静态

[英]Make JavaFX Application non static

I know that's maybe noob question and lot of others can find it useless, but I would be glad if someone could help me. 我知道这可能是一个新手问题,很多其他人都觉得它毫无用处,但是如果有人可以帮助我,我将感到非常高兴。

In every tutorial I saw making applications in JavaFX static like so: 在每个教程中,我都看到将JavaFX中的应用程序静态化,如下所示:

public class TestingApp extends Application
{

    @Override
    public void start( Stage primaryStage )
    {
        ...
    }

    public static void main( String[] args )
    {
        launch( args );
    }
}

but is there some way to define it non-static like so?: 但是有没有办法像这样定义它为非静态的呢?

public class TestingApp extends Application
{

    @Override
    public void start( Stage primaryStage )
    {
        ...
    }

    public TestingApp() {}

}

public class Main
{

    public static void main( String[] args )
    {
        TestingApp ta1 = new TestingApp()
        TestingApp ta2 = new TestingApp()

        ta1.launch( args )
        ta2.launch( args )
    }

}

I already saw this: Starting a second JavaFX Application , but it doesn't solve my problem. 我已经看到了: 启动第二个JavaFX Application ,但是它不能解决我的问题。

Per JVM instance you can only have one JavaFX application and one JavaFX application thread running. 每个JVM实例只能运行一个JavaFX应用程序和一个JavaFX应用程序线程。

But you can create multiple Stages (windows), if that is what you're looking for. 但是,如果您要查找的话,您可以创建多个舞台(窗口)。 The primary stage is provided by the start method but you can create secondary stages yourself. 主要阶段由start方法提供,但是您可以自己创建次要阶段。

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

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