Home > Uncategorized > Fixing Java applet not loading parameters

Fixing Java applet not loading parameters

Some years ago I had authored, in a bit of a hurry I should say, a small prototype educational application called Dr ASCII for usage in teaching about the ASCII table (character encoding defined by ANSI), binary numbers and bitmap (raster) fonts, in the context of an educational software and related teaching material proposal for Greek schools, that didn’t eventually succeed to get funded (mostly cause the partners authoring the teaching material samples didn’t have enough time either to dedicate on their development).

Luckily that online application did find some usage later on since my wife (Irene Mavrommati), a Graphics & Interaction designer, who has been teaching Graphics Design at the Hellenic Open University, decided to reuse Dr ASCII’s bitmap font editor and respective virtual terminal screen in the context of class project assignments having to do with bitmap font design.

I recently starting moving my various web stuff to a single place at Zoomicon.com. While reorganizing them I realized the various Dr ASCII webpages weren’t showing the expected content, with the Java applet they were embedding showing the same content on all of them. Because the applet was merely a container using dynamic class loading to load its content, I wondered at first whether something had changed with a Java applet’s ClassLoader and the rights of Java applets to load dynamically other classes even from the same JAR file container where its own class file is packed (btw a JAR file is just a ZIP file with a manifest.mf file in it – that manifest was originally required but has been made optional in later versions of Java).

I even checked my applet’s class file with HexEdit (a hex editor with a powerful free version) that can search for Unicode text (which Java uses) in binary files to see if the custom applet parameter I was using to inform the container applet of which component class to load, instantiate and host was using some different capitalization than the one in the HTML (that is in case Java was now asking for them to be case-sensitive, which wasn’t the case). When debugging / troubleshooting you have to be very suspicious – there are usually lots of things that can be conspiring to make a bug fire ;-).

The HTML pages were using the following code to embed the applet:

<APPLET
  CODEBASE = "."
  CODE        = "gr.birbilis.drascii.DrAsciiApplet.class"
  ARCHIVE = "jar/DrAscii.jar"
  NAME      = "drascii"
  WIDTH     = 100%
  HEIGHT   = 85%
  HSPACE  = 0
  VSPACE  = 0
  ALIGN     = middle
  myview   =  "gr.birbilis.drascii.game.BitmapFontEditor"
>
Sorry, your browser doesn’t support Java APPLETs
</APPLET>

I couldn’t see something wrong with that syntax since I remembered using it years ago (had made my first game applet back in 1997, more than a decade ago) with no issues. However I decided to double check how to get Java Applet parameters from an HTML page and noticed the example was using the PARAM tag to define applet parameters instead of listing them as attributes to the APPLET tag. The 2nd style was long ago introduced by Microsoft for use with its OBJECT tag (which W3C later on embraced in favor of Netscape’s EMBED and APPLET tags). So I tried changing the above to:

<APPLET
  CODEBASE = "."
  CODE        = "gr.birbilis.drascii.DrAsciiApplet.class"
  ARCHIVE = "jar/DrAscii.jar"
  NAME      = "drascii"
  WIDTH     = 100%
  HEIGHT   = 85%
  HSPACE  = 0
  VSPACE  = 0
  ALIGN     = middle
>
<PARAM NAME="myview" VALUE="gr.birbilis.drascii.game.BitmapFontEditor">
Sorry, your browser doesn’t support Java APPLETs
</APPLET>

Needless to say it worked fine. The only question remaining is if the PARAM syntax would work at very old browsers (left as an exercise to readers having an old browser and respective Java VM handy to try).

Advertisements
Categories: Uncategorized Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: