Geertjan is a DZone Zone Leader and has posted 466 posts at DZone. You can read more from them at their website. View Full User Profile

Applets Reloaded: An Overview of New Tags and Demos

04.10.2008
| 14136 views |
  • submit to reddit
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.

 

AttachmentSize
new-applet-1.png10.96 KB
new-applet-2.png39.21 KB
new-applet-3.png12.03 KB
new-applet-4.png63.14 KB
new-applet-5.png37.93 KB
new-applet-6.png15.78 KB
new-applet-8.png12.19 KB
new-applet-9.png36.73 KB
new-applet-91.png27.78 KB
new-applet-92.png13.19 KB
Published at DZone with permission of its author, Geertjan Wielenga.

Comments

cowwoc replied on Fri, 2008/04/11 - 9:12am

I thought we weren't supposed to use the <applet> tag anymore. Aren't we supposed to use that hidiously long <object> tag for modern browsers?

Vic Cekvenich replied on Fri, 2008/04/11 - 3:08pm

 

 

cowwoc:

You should look at what the home page of JavaLobby has for their rich tags.

They use actionscript for their little scolling messages.

(also FireFox verion 4.0 will come w/ actionscript built in).

 

.V

Michal Hlavac replied on Sun, 2008/04/13 - 4:10am

It doesn't work in linux using firefox. I get message "Click here to get the new Java Plug-in". But I am using 1.6.0_10beta.

Geertjan Wielenga replied on Sun, 2008/04/13 - 4:17am

It does work on Linux. I'm on Linux and it works fine. The problem is that you need FireFox 3, which is currently available in Beta versions only.

Michal Hlavac replied on Sun, 2008/04/13 - 4:31am

Yes, you are right. I am using firefox 2.x. Btw. are there some plans to support konqueror in linux?

Carla Brian replied on Sat, 2012/05/19 - 9:08pm

Thanks for sharing these sample tags. This might be helpful in the future. - DR Marketing Group

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.