简体   繁体   English

如何从Java类调用javafx类?

[英]How to call javafx class from java class?

I have called from my java class another javafx class as a background thread. 我从我的java类中调用了另一个javafx类作为后台线程。

     while(true)
     {
    ....
    .... (build new arguments)
    ....

    Thread t = new Thread() {
        public void run() {
            ChartData.main(arguments);
        }
    };
    t.start();
    }

I get an ERROR: 我收到一个错误:

Exception in thread "Thread-7" java.lang.IllegalStateException: Application launch must not be called more than once at om.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:94) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:75) at javafx.application.Application.launch(Application.java:209) 线程“ Thread-7”中的异常java.lang.IllegalStateException:不能在com.sun.javafx.application的om.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:94)处多次调用应用程序启动.LauncherImpl.launchApplication(LauncherImpl.java:75)在javafx.application.Application.launch(Application.java:209)

with javafx class I have constructed only a scatterplot and all my other objects have been achieved in java class. 使用javafx类,我仅构造了一个散点图,而我的所有其他对象都已在java类中实现。

Thank you for your Help. 谢谢您的帮助。

This is not the way JavaFX works. 这不是JavaFX的工作方式。

You have 2 options: 您有2个选择:

  1. make your program a proper JavaFX application, and just update the content of your drawing, GUI, or whatever. 使您的程序成为适当的JavaFX应用程序,然后只需更新图形,GUI或其他内容即可。 (You don't need an extra thread for this: just submit something to the UI thread with invokeLater.) (您不需要为此使用额外的线程:只需使用invokeLater将某些内容提交到UI线程即可。)

  2. Instead of a thread, run the separate JavaFX in its own process, see ProcessBuilder. 在线程中运行单独的JavaFX,而不是线程,请参阅ProcessBuilder。 Though this is more clean, you'll have to think abvout how to pass the data to show to the process 尽管这更干净,但您仍必须考虑如何将数据传递给流程

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

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