如果我用JavaFX内容关闭applet(因此applet正在使用EDT和JavaFX线程),jp2launcher.exe将继续运行将近1分钟,以便applet无法再次轻松启动(只要它不被识别为新实例 - 浏览器关闭后等)。
我搜索了Google,但我找不到解决方案。我发现只有非常相似的问题 - https://bugs.openjdk.java.net/browse/JDK-8051030。
另一种解决方案是,如果applet可以在持久的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){}}
}
答案 0 :(得分:1)
根据您的更新,
我无法在所显示的平台上重现问题;在选择退出applet和返回命令提示符之间的延迟没有明显增加。如果问题是特定于平台的,我已将该示例包含在测试参考中。
$ javac sample.java ; appletviewer sample.java
注意到的here,&#34;在小程序中,必须使用init
从invokeAndWait
方法启动GUI创建任务。&#34; Applet::start
为时已晚。
如果java.lang.IllegalStateException
为空或未初始化,我会在quit
上看到JFXPanel
。{/ p>
import javafx.embed.swing.JFXPanel;
import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
/*<applet code="sample" width=300 height=200></applet>*/
public class sample extends JApplet {
protected Scene scene;
protected Group group;
JFXPanel fxPanel;
@Override
public final void init() {
try {
SwingUtilities.invokeAndWait(this::initSwing);
} catch (java.lang.InterruptedException | java.lang.reflect.InvocationTargetException e) {
e.printStackTrace(System.out);
}
}
private void initSwing() {
fxPanel = new JFXPanel();
add(fxPanel);
Platform.runLater(() -> {
initFX(fxPanel);
});
}
private void initFX(JFXPanel fxPanel) {
group = new Group();
group.getChildren().add(new Label(
System.getProperty("os.name") + " v"
+ System.getProperty("os.version") + "; Java v"
+ System.getProperty("java.version")));
scene = new Scene(group);
fxPanel.setScene(scene);
}
}