Java Programming

Ah, Java applets. The scourge of the early internet. Everybody hated them yet so many sites loved using them. They eventually went out of favor, largely replaced by Flash, which then everyone hated. Unlike applets, even ancient Flash files still work today. Not applets though, for various reasons many of those old applets no longer function.

So what can you do with old applet that no longer works? I could say "delete it" but then this would be a really short article. Let's take it step further and also ask - what if you don't have the source code?

I recently found myself in this position. Before GeoCities shut down I archived a few favorites. GeoCities of course was a bastion of Java applets. One of the pages I archived was a Snatcher fan site. It had some kind of applet on the home page that sure didn't work:

Applet error

Yeah, that's IE6. A non-trivial percent of my traffic is still IE6 so I still test everything with it. Anyway, the error it was complaining about was:


	java.lang.NullPointerException
	  at sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel(Unknown Source)
	  at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	  at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	  at java.lang.Thread.run(Unknown Source)
	Exception: java.lang.NullPointerException

That sounds like a pretty darn easy error to fix. Without even seeing the source I just have a hunch this won't be tough. Doing a search for the error reveals there is likely a NoClassDefFoundError exception at the root of all this. Maybe this is as simple as recompiling the applet?

If the rest of this article sounds like a stream of consciousness it's because I'm writing it while trying to repair this applet.

The first step is to make sure the source code is really, truly gone and that no one has updated this applet. I don't know if the author of the site wrote this from scratch or used some public source code. Here's the HTML code for the applet:


	<applet code="HTick10.class" width="240" height="32">
	  <param name="BORDERWIDTH" value="0">
	  <param name="BORDERSTYLE" value="3">
	  <param name="BORDERCOLOR" value="#00CCCC">
	  <param name="TEXTFONT" value="Arial">
	  <param name="TEXTCOLOR" value="#FFFFFF">
	  <param name="BACKCOLOR" value="#000000">
	  <param name="SCROLLSPEED" value="30">
	  <param name="CAPTIONSPACE" value="10">
  <param name="CAPTION1" value="NEWS FOR MARCH 11th...">
  <param name="CAPTION2" value="Updated the links page, now includes a link to the online Snatcher script in Japanese. More to come soon I hope...">
	</applet>

A Google search for "HTick10 applet" doesn't turn up much. There's one page in Italian that's distributing it but according to the Google translation "the images and files that supplies were procured in the network from sites Free and intellectual property of those files remain in their legitimate authority" so I doubt this is the author.

Guess I'll be decompiling the code then. Finally, a good excuse to install the JAD plug-on for Eclipse. Let's add https://jadclipse.sf.net/update [note: this is an old article and the link has likely changed] to the list of update sites and install it:

Adding JAD to Eclipse

Decompiling the code revealed the original author:


	public String getAppletInfo()
	{
	  return "HTick10 v1.00 release\r\n(c) Java Hermit 1998\r\nwww.celticedge.com/hermit/";
	}

That page is down now, or at least under perpetual construction. On a related note "Celtic Edge" sounds like a great name for a new deodorant.

How about we paste this code into a new applet project, starting fresh, like the fresh aroma of Celtic Edge:

Missing class

Alright, I totally called the NoClassDefFoundError exception (well, actually Sun did). There's a dependency on a HTick10a class that's missing. Guess I gotta go back to that Italian site and see if they have the missing class in their download. Sure enough they do and all is well now:

Applet running

OK, it's not totally well. There are some deprecated APIs being used which is expected from 11 year-old code:


    public void init(){
	  setLayout(null);
	  d = size();
	  z20 = new HTick10av2();
	[...]
	void z21(Dimension dimension,int i){
	  z24=dimension.width-i*2;
	  z25=dimension.height-i*2;
	  reshape(i,i,z24,z25);
	  FontMetrics fontmetrics=getFontMetrics(getFont());

Let's go ahead and update those. Since this is decompiled code the method and member names are pretty meaningless so let's clean them up while we're at it. Some other minor changes, like having default parameter values for testing, would be nice too.

After making those updates here's the final product:


Download

Source code and class files



Related