Better Applet Deployment with Applet-Fu

Although JavaScript (i.e., AJAX) can be used in many situations to create interactive controls on Web pages, advanced user interfaces that perform extensive manipulation of domain-specific models may not be a good match for the approach. In those situations, Applets are a good option. However, the Web has changed a lot since applets were introduced in the mid 1990s and documentation hasn't kept up well. Consequently, a lot of information is out of date or simply inaccurate. This article discusses a tool to make applet deployment easier.

Applet-Fu is a small JavaScript library for deploying Java applets. Its main features are:

  • Avoids "Click to activate" message on some Internet Explorer versions.
  • Lets you specify a minimum Java plugin version to run the applet.
  • Makes it easy to include alternative interactive content in the event that the minimum plugin version is not detected.
  • If the correct Java plugin version is not installed, takes advantage of the browser's built-in mechanism for installing it without taking the user to a different site.
  • Eliminates the <applet> tag, which is deprecated in HTML 4.

To use Applet-Fu, include the applet-fu.js file in your <head> element and call applet_fu.run. For example, to run an a 550x320 applet from the jar file 'myapplet.jar' using the class com.example.MyApplet' with a startup parameter 'foo=bar', a minimum JVM version of 1.4.2, and an image called 'no-java.png' as fallback content, use the following:

applet_fu.run(
  {'width':'550','height':'320'},
  {
    'archive':'myapplet.jar',
    'code':'com/example/MyApplet.class',
    'foo':'bar'
  },
  '1.4.2',
  '<img src="/no-java.png" />'
);

Sun Microsystems have released a heavier JavaScript applet toolkit called Java Deployment Kit. The main advantage of Applet-Fu is simplicity, documentation, and ease of use. If your application requires a more full-featured approach, Sun's solution might be worth looking at.

Applet-Fu is the preferred method for deploying ChemWriter, the 2D chemical structure editor for Web applications. The new chemwriter.com site gives several concrete examples of using Applet-Fu. For example, you might try disabling (or uninstalling) Java in your browser to see the simple process that a user would follow to get ChemWriter working.

Applet-Fu is known to work on all versions of the Java Plugin higher than 1.4.2, all modern browsers including Internet Explorer 6/7/8, Firefox 3, Safari 3, and Opera 9, and all major OSes including Windows, Mac, and Linux. In the event that you do find a problem with Applet-Fu, please consider filing a bug report.

Comments

  1. dreas
    July 09, 2009 @ 3:12 PM

    Very handy, thanks for sharing this script! It even works in Google Chrome!

  2. nacho
    August 04, 2009 @ 2:35 PM

    hey, thanks a lot for sharing the code with everybody.

    I just wanted to confirm, should this avoid IE requiring me to Activate ActiveX controls? Because it still does and I understood that it shouldn't.

  3. Rich Apodaca
    August 05, 2009 @ 1:36 PM

    @naco, yes, you shouldn't get the 'click to activate' message for Java applets. What version of IE and the Java plugin are you using?

Your thoughts?

No HTML. To create a link like this example, use: [example](http://example.com). Learn more