如果我关闭带有 JavaFX 内容的小程序(因此小程序使用 EDT 和 JavaFX 线程),jp2launcher.exe 将继续运行近 1 分钟,因此小程序无法轻松再次启动(一旦它未被识别为新实例 - 在浏览器关闭后ETC。)。
我搜索了谷歌,但我没有找到解决方案。我只发现了非常相似的问题——https: //bugs.openjdk.java.net/browse/JDK-8051030。
另一种解决方案是,如果小程序可以在持久的 jp2launcher.exe 上启动,但它不能。它根本没有被调用。只有 JApplet 的 init 方法被覆盖。
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import java.awt.Graphics;
import javafx.embed.swing.JFXPanel;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.animation.Timeline;
/*<applet code="sample" width=600 height=600></applet>*/
public class sample extends JApplet{
protected Scene scene;
protected Group group;
Timeline timeline;
JFXPanel fxPanel;
@Override
public final void init(){initSwing();}
private void initSwing(){
fxPanel = new JFXPanel();
add(fxPanel);
Platform.runLater(() ->{initFX(fxPanel);});
}
private void initFX(JFXPanel fxPanel){
timeline=new Timeline();
group=new Group();
scene=new Scene(group);
}
@Override
public void start(){
try{SwingUtilities.invokeAndWait(this::initSwing);}
catch(java.lang.InterruptedException|java.lang.reflect.InvocationTargetException e){}}
}