两次调用JavaFX应用程序 [英] Call JavaFX application twice

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

问题描述

我需要以下帮助:我正在javafx中实现一个应用程序,该应用程序是通过单击按钮来调用的. 问题是,当我关闭应用程序时,无法再次调用它. 我读到您不能多次调用Application.launch()方法. 但是我在服务类上发现了一些东西.文档页面中的示例不是很清楚.任何人都知道如何做到这一点? 谢谢.

I would need help with the following: I am implementing an application in javafx, this application Is called through a click on a button. The problem is that when I close the application then I can not call it again. I have read that you can not call the Application.launch() method more than once. But I found something on the service class. The examples in the documentation page are not very clear. Anyone have an idea of ​​how this could be done? Thank you.

http://docs.oracle.com/javafx/2 /threads/jfxpub-threads.htm

我的代码:

private void jButton1ActionPerformed (java.awt.event.ActionEvent evt) {

      WebMap n1 = new WebMap () / / application in javafx

      n1.Lunch ();
}


WebMap类://Javafx应用程序


WebMap class: / / javafx application

public void Lunch () {
     Application.launch ();
}

推荐答案

您不能在同一过程中多次启动JavaFX应用程序,因此不要尝试这样做.

You can't launch a JavaFX application more than once in the same process, so don't try to do that.

您需要找到一种替代机制来执行您要尝试执行的操作.

You need to find an alternative mechanism to do whatever it is you are trying to do.

如果要将JavaFX场景嵌入到Swing应用程序中,则应该在Swing中创建新的JFXPanels,而不是在按Swing按钮时创建新的JavaFX Application.

If you are embedding JavaFX scenes in a Swing application you should be creating new JFXPanels in Swing, not creating new JavaFX Applications on Swing button presses.

如果您打算有一个纯JavaFX应用程序,那么就不需要有一个Swing按钮来启动JavaFX应用程序,您只需使用JavaFX按钮即可直接显示JavaFX场景.

If you are intending to have a pure JavaFX application, then there is no need to have a Swing button which launches a JavaFX application, you can just use a JavaFX button instead and directly display the JavaFX scene.

在这种情况下,无需使用Service,Service用于在另一个线程上执行重复的后台任务,这与您尝试执行的操作无关.

There is no need to use a Service in this case, Service is used for performing repeated background tasks on a another thread, which has nothing to do with what you are attempting.

如果要集成,请阅读面向Swing开发人员的JavaFX Swing和JavaFX应用程序.

Read JavaFX for Swing developers if you want to integrate a Swing and JavaFX application.

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

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