Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Applet in WebView

I am trying to display a Java Applet in a Java FX WebView. However, as far as I've been able to figure, it is not possible.

How can I accomplish this, without the Java FX WebView?

like image 498
Maeh Avatar asked Jan 14 '15 18:01

Maeh


2 Answers

I have gotten this working before. I eventually gave up on JavaFX as a Java Applet for the video game i was making, due to performance issues, but it is still valid for many other purposes. Here is the config I used.

<html><head>
  <SCRIPT src="http://java.com/js/dtjava.js"></SCRIPT>
<script>
    function launchApplication(jnlpfile) {
        dtjava.launch(            {
                url : 'MyGame.jnlp'
            },
            {
                javafx : '2.2+'
            },
            {}
        );
        return false;
    }
</script>

<script>
    function javafxEmbed() {
        dtjava.embed(
            {
                url : 'MyGame.jnlp',
                placeholder : 'javafx-app-placeholder',
                width : 1024,
                height : 768
            },
            {
                javafx : '2.2+'
            },
            {}
        );
    }
    <!-- Embed FX application into web page once page is loaded -->
    dtjava.addOnloadCallback(javafxEmbed);
</script>

</head><body>
<h2>Test page for <b>MyGame</b></h2>
  <b>Webstart:</b> <a href='MyGame.jnlp' onclick="return launchApplication('MyGame.jnlp');">click to launch this app as webstart</a><br><hr><br>

  <!-- Applet will be inserted here -->
  <div id='javafx-app-placeholder'></div>
</body></html>

I used JNLP to do this. Here is my JNLP file.

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0" xmlns:jfx="http://javafx.com" href="MyGame.jnlp">
  <information>
    <title>MyGame</title>
    <vendor>Jose</vendor>
    <description>Sample JavaFX 2.0 application.</description>
    <icon href="C:\Users\jose\Dropbox\MyGame\java7\MyGame/MyGame.ico" />
    <offline-allowed/>
  </information>
  <resources>
    <jfx:javafx-runtime version="2.2+" href="http://javadl.sun.com/webapps/download/GetFile/javafx-latest/windows-i586/javafx2.jnlp"/>
  </resources>
  <resources>
    <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="MyGame.jar" size="27670609" download="eager" />
  </resources>
  <applet-desc  width="1024" height="768" main-class="com.javafx.main.NoJavaFXFallback"  name="MyGame" >
    <param name="requiredFXVersion" value="2.2+"/>
  </applet-desc>
  <jfx:javafx-desc  width="1024" height="768" main-class="game.Game"  name="MyGame" />
  <update check="background"/>
</jnlp>

Hope this helps. Let me know if you have any follow up questions.

like image 61
Jose Martinez Avatar answered Nov 08 '22 17:11

Jose Martinez


JavaFX Web View doesn't support applets so it won't work for you. You should consider another embedable browser like JCEF or JWebBrowser from NativeSwing or some other component

like image 1
bedrin Avatar answered Nov 08 '22 18:11

bedrin