For deploying JavaFX in browser, we use JavaScript code as shown below

<script src="http://dl.javafx.com/1.1/dtfx.js"></script>
<script>
    javafx(
        {
              archive: "JavaFX_Flickr_Image_Viewer.jar",
              draggable: true,
              width: 800,
              height: 650,
              code: "carousel.Main",
              name: "JavaFX_Flickr_Image_Viewer"
        }
    );
</script>

JavaFX uses dtfx.js which in turn uses deployJava.js to detect presence of java, the version of java on the system etc. Refer to Java Deployment Toolkit documentation for more information.

So how does JavaFX deploys as Applet without using Applet tag?

It indeed uses Applet tag, dtfx.js script generates the required Applet tag. It generates two <div> sections. The first section shows the spinning java logo and second sections embeds the Applet. First the spinning logo is shown, when applet is loaded, its visibility status is changed to false.

The generated html tags will be as shown below, which has embedded Applet tag

<script src="http://dl.javafx.com/1.1/dtfx.js"></script>
<div id="deployJavaApplet1Overlay" 
    style="width:800;height:650;position:absolute;background:white">
    <table width=800 height=650 border=padding=margin=0>
    <tr><td align="center" valign="middle">
        <img src="http://dl.javafx.com/javafx-loading-100x100.gif" width=100 imgHeight=100>
    </td></tr>
    </table>
</div>
<div id="deployJavaApplet1" style="position:relative;left:-10000px">
    <APPLET MAYSCRIPT
        code="org.jdesktop.applet.util.JNLPAppletLauncher"
        archive="JavaFX_Flickr_Image_Viewer.jar,
        http://dl.javafx.com/applet-launcher__V1.1.1.jar,
        http://dl.javafx.com/javafx-rt__V1.1.1.jar,
        http://dl.javafx.com/fxdloader__V1.1.1.jar,
        http://dl.javafx.com/jmc__V1.1.1.jar,
        http://dl.javafx.com/Decora-SSE__V1.1.1.jar,
        http://dl.javafx.com/emptyJarFile-1239792034654__V1.1.1.jar"
        width=800
        height=650>
        <param name="codebase_lookup" value="false">
        <param name="subapplet.classname" value="com.sun.javafx.runtime.adapter.Applet">
        <param name="progressbar" value="false">
        <param name="classloader_cache" value="false">
        <param name="draggable" value="true">
        <param name="MainJavaFXScript" value="carousel.Main">
        <param name="subapplet.displayname" value="JavaFX_Flickr_Image_Viewer">
        <param name="jnlpNumExtensions" value="2">
        <param name="jnlpExtension1" value="http://dl.javafx.com/jmc__V1.1.1.jnlp">
        <param name="jnlpExtension2" value="http://dl.javafx.com/Decora__V1.1.1.jnlp">
        <param name="jnlp_href" value="JavaFX_Flickr_Image_Viewer_browser.jnlp">
        <param name="deployJavaAppletID" value="deployJavaApplet1">
    </APPLET>
</div>

How will we get this generated Applet tag?

Just add displayhtml: true as shown below. This will display the html instead of loading the applet!

<script src="http://dl.javafx.com/1.1/dtfx.js"></script>
<script>
    javafx(
        {
              archive: "JavaFX_Flickr_Image_Viewer.jar",
              draggable: true,
              width: 800,
              height: 650,
              code: "carousel.Main",
              name: "JavaFX_Flickr_Image_Viewer",
              displayhtml: true
        }
    );
</script>



Comments:

Good article. I did not know about the displayhtml attribute. Thanks for pointing that out.

I also wrote an article about JavaFX deployment that other readers may find useful:

http://www.dieajax.com/2008/12/19/10-minute-javafx-tutorial-deploy-javafx-applets-and-applications-both-online-and-offline/

Posted by David Miles on April 16, 2009 at 01:17 AM IST #

Thanks David. I liked the article. Yes I think we must stress more on javafxpackager utility. Thanks for sharing it.

Posted by Rakesh Menon on April 16, 2009 at 09:46 AM IST #

<script>
javafx(
{
archive: "JavaFX_Flickr_Image_Viewer.jar",
draggable: true,
width: 800,
height: 650,
code: "carousel.Main",
name: "JavaFX_Flickr_Image_Viewer",
}
);
</script>

The script above will produce an error with IE.

The trailing comma will cause an error.

name: "JavaFX_Flickr_Image_Viewer",

Should be:

name: "JavaFX_Flickr_Image_Viewer"

Posted by Greg on April 16, 2009 at 10:53 AM IST #

Thanks Greg for pointing out. I fixed it. I just removed the line "displayhtml: true" but didn't remove the "," and also didn't try in IE.

Posted by Rakesh Menon on April 16, 2009 at 11:01 AM IST #

hi rakesh i converted another demo from flash to JavaFX please see i start working on my small website on which i will post article and demos just for learning purpose.
i have some questions
In flash there is function loadLibrary(.swf) that will loadd swf at user request this is very useful function suppose there is a contact link button in website and user is not intererted in viewing that so it is ineffecient to load that jar file can we do that kind of stuff in javafx on user request the demo will be loaded and shown in progress bar..

Posted by Farrukh Obaid on April 17, 2009 at 03:44 AM IST #

@Farrukh Your demos look cool! JavaFX does not directly provide loadLibrary like functionality. I tried to get some info from engineers, basically I wanted to explore feasibility of using custom ClassLoaders. But not fully successful yet.

Posted by Rakesh Menon on April 20, 2009 at 11:20 AM IST #

How to provide parameters to run your own JavaFX applet?

Posted by Chunyen Liu on June 03, 2009 at 03:44 AM IST #

@Chunyen Liu you can refer to below post
http://blogs.sun.com/rakeshmenonp/entry/javafx_passing_arguments

Posted by Rakesh Menon on June 11, 2009 at 03:03 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blog copyright 2009 by Rakesh Menon