启动第二个JavaFX应用程序 [英] Starting a second JavaFX Application

查看:96
本文介绍了启动第二个JavaFX应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从JavaFx应用程序中启动JavaFx应用程序,但看起来Application.launch()只能被调用一次。这是否意味着我必须启动一个单独的JVM ...就像在exec中一样(java ......还是有另一种方式?

I'm trying to launch a JavaFx application from within a JavaFx application, but it looks like Application.launch() can only be called once. Does this mean I have to start a separate JVM... as in exec("java... or is there another way?

更多背景信息。我想要我的JavaFx应用程序能够构建和运行JavaFx应用程序。现在它在内存中编译类,加载类......真的很遗憾不得不求助于将所有内容写入文件系统,这样我就可以获得一个jar文件系统,所以我可以使用exec来启动它。

More background info. I want my JavaFx app to be able to build and run JavaFx apps. Right now it compiles classes in-memory, loads the classes... it would be really unfortunate to have to resort to writing everything to the filesystem so I can get a jar on the filesystem, so I can use exec to start it up.

作为第二个问题...有没有办法打开另一个JavaFx窗口并获得阶段并传递它到我新编译和加载的Application子类?

As a secondary question... Is there a way to open another JavaFx window and get the stage and pass it to my newly compiled and loaded Application sub-class?

推荐答案

如果你想在同一个JVM中执行另一个JavaFX应用程序你可以只需创建它的实例,手动创建 Stage 并调用应用程序#start()

If you want to execute another JavaFX application in the same JVM you can just create instance of it, manually create Stage and call Application#start()

public void runAnotherApp(Class<? extends Application> anotherAppClass) throws Exception {
    Application app2 = anotherAppClass.newInstance(); 
    Stage anotherStage = new Stage();
    app2.start(anotherStage);
}

注意:如果您使用标准初始化的特殊功能,它将无效另一个,例如 Application.init() Application.getParameters()

N.B.: it wouldn't work if you use special features of standard initialization in anotherApp, e.g. Application.init() or Application.getParameters()

这篇关于启动第二个JavaFX应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆