Applets Reloaded: An Overview of New Tags and Demos

DZone 's Guide to

Applets Reloaded: An Overview of New Tags and Demos

· Java Zone ·
Free Resource
What's the deal with applets in JDK 6 Update 10? In this article, we walk through the new applet tags and see some JNLP-powered applets in the wild.

If you're used to creating applet tags that look like this:

<applet code="org.me.hello.MyApplet" archive="HelloApplet.jar"></applet>

...then you're in for a surprise. Here are the new parameters that you should be aware of:

  • "jnlp_href". Probably the most important new parameter, it lets you launch an applet from a JNLP (web start) file.
  • "boxborder". Offers support for the "image" attribute, specifying whether a one-pixel border should be drawn around the edge of the applet's area while displaying the image shown before the applet is loaded.
  • "centerimage". Offers support for the "image" attribute, specifying whether the loading image should be centered within the area of the applet instead of originating at the upper left corner.
  • "java_arguments." Specifies JVM command-line arguments to be used when executing this applet instance. Nearly all JVM command-line arguments are supported, though there are certain rules and restrictions.
  • "java_version." Specifies a JRE version upon which to launch a particular applet.
  • "separate_jvm." Specifies a separate JVM for an applet, specifically for powerful applets that cannot tolerate interference during deployment.
  • "classloader_cache." Lets an applet opt out of the use of the class loader cache on an applet by applet basis.

For a full description of the above new parameters, see Release Notes for the Next-Generation Java™ Plug-In Technology. You will find that the improvements for applets in JDK 6 Update 10 are as follows:

  • Improved reliability. The JVM running the applet is isolated from the web browser at the operating system level. If something should go wrong while running the applet, or if an uncooperative applet refuses to shut down, the new Java Plug-In detects and handles the error condition gracefully; the web browser is unaffected.
  • Built-in JNLP support. The new plug-in offers the capability to launch applets directly from JNLP files, unifying deployment of Java content both in the browser and out of the browser (via Java Web Start). Developers can now reuse JNLP extensions for advanced functionality including the JavaFX run-time libraries, 3D graphics via OpenGL, and planetary-scale terrain visualization within applets. Applets can now access JNLP APIs for persistent data storage, local file system access, and other useful functionality from sandboxed code.
  • Per-applet command-line arguments. JVM command-line arguments may be specified on a per-applet basis, providing fine-grained control over options such as the heap size and Java 2D hardware acceleration features. JNLP-launched applets simply incorporate the command-line arguments and/or system properties into the JNLP file. Old-style applets can embed these arguments in the HTML of the web page.
  • Multiple JRE version support. Each individual applet instance may request a different JRE version on which to run. This feature is designed for enterprise customers which prefer to qualify their applets against either a particular JRE version or a particular JRE family. Both selection of a specific JRE version, or any in a particular family, are supported in the new plug-in.
  • Improved Java/JavaScript communication. The bridge between the JavaScript engine in the web browser and the Java programming language has been completely reimplemented. The new implementation is backward-compatible and features improved reliability, performance and cross-browser portability, for both Java calling JavaScript as well as JavaScript calling Java. Formerly Mozilla-specific "LiveConnect" functionality, such as the ability to call static Java methods, instantiate new Java objects and reference third-party packages from JavaScript, is now available in all browsers.
  • Improved user experience. The new Java Plug-In starts applets in the background, so the web browser always remains responsive. Applets appear on the web page as they become ready to run.
  • Improved applet lifecycle management. Calls to the applet lifecycle methods init, start, stop, and destroy are more deterministic and cross-browser behavior has been improved. The applet class loader cache and the legacy applet lifecycle, required for backward compatibility, are fully supported and the behavior of both has been improved.
  • Better large heap support. Historically, the maximum heap size that could be specified for applets via the Java Control Panel has been limited. This limitation is fixed in the new Java Plug-In; applets can now utilize as much heap space as command-line applications.
  • Better Windows Vista support. Signed applets running in Protected Mode Internet Explorer on Microsoft's Windows Vista now have the same privileges as normal user applications, eliminating a portability barrier to this platform.

To get started using the new support for applets, including the above tags, you need JDK 6 Update 10 Beta. If you are using FireFox, you also need some beta version of FireFox 3. The above release notes state, on this point: "Sun Microsystems and the Mozilla Foundation have been working closely in order to support the new Java Plug-In in Firefox 3. Both organizations have mutually decided not to back-port the required changes — which are significant — to Firefox 2, as it is expected that most Firefox users will upgrade to Firefox 3 a short time after its final version has been released."

Several examples are already available of the new applet technology in action. I must say that I find them pretty convincing: smooth, no browser freezing, very nice indeed.

NASA World Wind Applet

Shows how to embed the Earth in full 3D on a web page. Click here for all the deployment info.

Jake2 Applet

Game deployment over the web? Check out this one for a great and fun example. Click here for deployment info.

Scene Graph Applets

The Scene Graph applets are pretty excellent, showing the power of the new Scene Graph together with the power of the new browser Java plugin. Here's the whole list of them:

Calculator. A simple, functioning, calculator application:

SnowMark. Illustrates the use of images, transformations, and effects such as shadows and Gaussian blurs. Click the demo to pause / resume the animation:

Egg Timer. A functioning "egg timer" example which can be set for up to 59 minutes:

Dynamic Demo. Shows several hundred dynamically moving shapes in the scene. Click the demo to pause / resume the animation:

JPhone. An example of a modern cell phone UI written using Scene Graph:

NestedText. An example of a JSGPanel nested inside an SGComponent, which is part of the scene of another JSGPanel:

JavaFX Timer Applet

How about JavaFX in an applet? The cool thing is that you also see the source code, when you go to the site.

Finally, I had to try it out myself. I created a small applet, added some Swing components, and deployed it via a JNLP file. First I deployed it to FireFox 2 and got the same old terrible performance. Deployed to FireFox 3, it was a breeze. There's some kind of very gentle introduction of the applet to the browser whereby it seems to unfold before your eyes as it is deployed to the page. A very nice professional effect. And then my applet appeared:

Also, because of the JNLP support, applets can access JNLP APIs for persistent data storage, local file system access, and other useful functionality from sandboxed code. All the information you should ever need can be found in Release Notes for the Next-Generation Java™ Plug-In Technology and, especially, in JNLP Support in the New Java Plug-in Technology.



Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}