The new applet experience

Applet development with JavaFX Script and Java SE 6u10

1 2 3 4 Page 4
Page 4 of 4

Deploying the applet via the online and kernel installers

The Java Deployment Toolkit defaults to installing only general availability (GA) versions of Java SE -- Java.com reports update 5 as the most recent GA version. To install update 10, you need to take advantage of a deployJava.js feature that lets you install a pre-GA -- early access (EA), beta, or release candidate (RC) -- version. Listing 5 demonstrates this feature.

Listing 5. Weather2online.html

<html>
  <head>
    <script src="http://java.com/js/deployJava.js">
    </script>
  </head>

  <body>
    <script>
      var attributes =
      {
        code: 'javafx.ui.Applet',
        width: 375,
        height: 375,
        archive: 'javafxrt.jar,Scenario.jar,Weather.jar'
      };

      var parameters =
      {
         AppletClass: 'Weather',
         image: 'title.jpg',
         centerimage: true,
         boxborder: false
      };

      var version = '1.6.0';

      deployJava.setEarlyAccess ('true');
      deployJava.EarlyAccessURL = 'http://javadl.sun.com/webapps/download/GetFile/1.6.0_10-beta-b14/
                                   windows-i586/jre-6u10-beta-windows-i586-p-iftw.exe';
      deployJava.runApplet (attributes, parameters, version);
    </script>
  </body>
</html>

The feature consists of a setEarlyAccess(enabled) function, which must be invoked with a string argument set to "true", and an EarlyAccessURL attribute, which must be assigned the path and name of an appropriate installer. I've specified the URL for the Java SE 6 update 10 beta build 14 online installer.

URLs in code snips
Because the URL in Listing 5 is too long to fit on one line (for listing purposes), I've spread it across two lines. In contrast, the Weather2online.html file included in this article's code archive specifies this URL on a single line.

In addition to making it possible to install update 10 via the online installer, Listing 5 introduces the new Java Plug-in's centerimage and boxborder parameters. These parameters let you center the starting image (title.jpg, for example) in the applet's rectangular browser area, and remove the one-pixel border that's drawn around this area to seamlessly merge the applet with surrounding content.

Before installing update 10, remove update 5 from your platform (to prevent runApplet() from deferring to it). Then point your browser to Weather2online.html, which results in jre-6u10-beta-windows-i586-p-iftw.exe downloading to your desktop. Double-click this installer's icon. In response, it starts downloading JRE installation files while displaying Figure 7's dialog box.

The progress bar reports the state of the download.
Figure 7. The progress bar reports the state of the download. (Click to enlarge.)

This dialog box is followed by a sequence of dialog boxes beginning with those shown earlier in Figures 4 and 5. Click Finish on the "Java Setup - Complete" dialog box to complete the installation. In response, runApplet() automatically starts the Weather applet (which it couldn't do in the context of update 5 because of the manual install). Figure 8 reveals the security dialog box and the starting image.

Click the Run button to run the applet.
Figure 8. Click the Run button to run the applet. (Click to enlarge.)

Enter the Java Plug-in

You might also notice that the screenshot in Figure 8 reveals the presence of Java SE 6u10's new Java Plug-in, which you can see by the effect of the plugin's centerimage and boxborder parameters on the starting image. If you launch the Windows Task Manager, you'll notice that update 10's Java Quick Starter process jqs.exe is running, which results in faster applet startups.

You'll also discover the Deployment Toolkit Plugin, a browser plugin designed to interact with deployJava.js. The idea is for runApplet() to access the plugin to obtain a list of installed JREs, install a specific JRE or the latest JRE, and perform other tasks. In the future, runApplet() will probably, via the plugin, default to downloading and launching the kernel installer.

Two Deployment Toolkit Plugin implementations
There are two implementations of the Deployment Toolkit Plugin. The Mozilla Firefox Netscape API-based implementation is contained in npdeploytk.dll, which is located in the browser's plugins directory, and is identified by MIME type application/npruntime-scriptable-plugin;DeploymentToolkit. Similarly, the Internet Explorer ActiveX Control-based implementation is contained in deploytk.dll, which is located in the windows\system32 directory, and is identified by ClassID CAFEEFAC-DEC7-0000-0000-ABCDEFFEDCBA.

Unlike the online installer, the kernel installer (Java Kernel) downloads only those JRE files needed to get the applet running. This installer then downloads the remaining files while the user interacts with the applet.

You can try out the kernel installer by using the HTML file presented in Listing 6. This HTML file differs from its predecessor via the presence of the kernel installer's URL, which is assigned to EarlyAccessURL, and via the presence of deployJava.setInstallerType ("kernel");, which sets the installer type to the kernel installer.

Listing 6. Weather2kernel.html

<html>
  <head>
    <script src="http://java.com/js/deployJava.js">
    </script>
  </head>

  <body>
    <script>
      var attributes =
      {
        code: 'javafx.ui.Applet',
        width: 375,
        height: 375,
        archive: 'javafxrt.jar,Scenario.jar,Weather.jar'
      };

      var parameters =
      {
         AppletClass: 'Weather',
         image: 'title.jpg',
         centerimage: true,
         boxborder: false
      };

      var version = '1.6.0';

      deployJava.setEarlyAccess ('true');
      deployJava.EarlyAccessURL = 'http://javadl.sun.com/webapps/download/GetFile/1.6.0_10-beta-b14/
                                   windows-i586/jre-6u10-beta-windows-i586-p-iftw-k.exe';
      deployJava.setInstallerType ("kernel");
      deployJava.runApplet (attributes, parameters, version);
    </script>
  </body>
</html>

Before installing update 10 via the kernel installer, remove the update 10 previously installed via the online installer. Then point your browser to Weather2kernel.html, which results in jre-6u10-beta-windows-i586-p-iftw-k.exe downloading to your desktop. Double-click this installer's icon. You should experience a faster installation, and notice Figure 9's dialog box periodically popping up.

This dialog box pops up when additional JRE components are being downloaded and installed.
Figure 9. This dialog box pops up when additional JRE components are being downloaded and installed. (Click to enlarge.)

Toward the future

Although it took me some time to adjust to JavaFX Script, I've found this technology to be helpful for developing applets. I especially appreciated the compiled version of JavaFX Script, its declarative syntax, and the language's binding feature. Despite the threading problem I mentioned (which should be resolved as compiled JavaFX Script matures), I think that JavaFX Script will prove to be a very attractive alternative to Java for creating applets, especially as its documentation improves and rich media becomes accessible via this language.

Overlooking some awkwardness that should be resolved in the future, I've found that the Java Deployment Toolkit makes it easier to deploy an applet and a suitable JRE. I also found that the Java Kernel offers faster deployment, and that Java Quick Starter results in faster applet startup times. While I didn't do much with the new Java Plug-in, such as attempt to run applets via JNLP, it was nice to see the Java Plug-in's support (via centerimage and boxborder) for integrating applets seamlessly into Web pages.

For broader conclusions about using applets and other Java technology for consumer and rich internet application development, see this article's companion piece: "Are applets making a comeback?"

Jeff Friesen is a freelance software developer and educator who specializes in Java technology. Check out his javajeff.mb.ca website to discover all of his published Java articles and more.

Learn more about this topic

Technology downloads

More from JavaWorld

1 2 3 4 Page 4
Page 4 of 4