2016-05-03 15 views
1

アプレットをJavaFXコンテンツで閉じると(アプレットがEDTとJavaFXスレッドを使用しているため)、jp2launcher.exeがほぼ1分間実行され、アプレットを簡単に再開できなくなります新しいインスタンスとして認識されないため、ブラウザの終了後など)。jp2launcher.exeがアプレットを閉じて終了しない

Googleで検索しましたが、解決策は見つかりませんでした。私は非常に似た問題 - 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){}} 
} 
+0

[MCVE]含めるようにあなたの質問を編集してください。アプレットには[this](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html)も必要です。 – trashgod

+0

私はこの動作のいくつかの合理的な長いサンプルを作っていますが、その短さのため、* jp2launcher.exe *は非常に遅れて終了しますが、アプレットの終了に伴って終了しないことがわかります。 –

答えて

1

  • 私が示したプラットフォーム上で問題を再現することができません。アプレットを終了してからコマンドプロンプトに戻るまでに遅延が認識されなくなります。問題がプラットフォーム固有のものである場合は、参考のためにテストされた例を含めました。

    $ javac sample.java ; appletviewer sample.java 
    
  • Aはhereを指摘し、 "アプレットは、GUI-作成タスクは、invokeAndWaitを用いinit方法から起動しなければなりません。" Applet::startが遅すぎます。

  • 例外を破棄するまで使用されていないため、JFXPanelが空または未初期化の場合、java.lang.IllegalStateExceptionquitに表示します。

image

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); 
    } 
} 
関連する問題