Running Swing Applets




Problem?

If you're developing Java now, chances are you're using Swing. If someone's using an old browser, chances are your applet won't run. Typically if you wanted to have an applet run in your webpage the code you'd use would look something like this.

<APPLET code="foo.class" codebase="html/" align="baseline"
    width="200" height="200">
<PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
    No Java 2 SDK, Standard Edition v 1.3 support for APPLET!!
</APPLET>
	
When your browser hits the <APPLET> tag it starts up the browsers JVM (Java Virtual Machine), but if the person viewing the web page has an old browser, it's unlikely their JVM will support Swing so they won't be able to view your applet.

Solution?

The JRE1.3 (Java Runtime Environment 1.3) comes with the Java Plug-In. Using the Java Plug-In, any browser, no matter how old should be able to run your applet. But because your browser will invoke the default JVM when it hits the <APPLET> tag, to call the Plug-In the <OBJECT> tag is used instead.

The HTML code for using the <OBJECT> tag looks a lot more complicated:

<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="200" height="200" align="baseline"
    codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
    <PARAM NAME="code" VALUE="foo.class">
    <PARAM NAME="codebase" VALUE="html/">
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
    <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
    <PARAM NAME="scriptable" VALUE="true">
        No Java 2 SDK, Standard Edition v 1.3 support for APPLET!!
</OBJECT>

Fortunatley, this isn't a problem. The HTML Converter which can be downloaded from java.sun.com will sort out all your worries. Run the HTML converter, select the folder and it will automatically convert any HTML files so that they'll invoke the Plug-In.

Anything else I should know?

  • Running appletviewer on a HTML file with unconverted code works, but the same file won't work in my browser. Why?
    Running appletviewer will automatically invoke your JRE, it's completely seperate from your browser which is why you need to change the HTML code so your browser will invoke the Plug-In.

  • My browser runs unconverted HTML no problems. Do I need to run the converter?
    Yes. Just because your browser runs your applet fine, don't presume that everyone else's does too. If you run the code converter, anyone will be able to run your applet, regardless of their type of browser, just as long as they have the Java Plug-In.

  • One last thing - if you make some changes to and recompile your applet, when you refresh your browser you'll probably notice that it won't reflect the changes you've just made. That's because your browser is grabbing the applet from its cache. To make sure it runs the new version, hit Ctrl-Refresh or Ctrl-Reload. Just in case that doesn't work (it mightn't with IE5.5) go Start/Run and type
    IExplore.exe -new D:\Yourcode\applet.html
    The -new ensures the cache is cleared.

    IDEs

    Menu
  • Last updated August 15th 2000