Thursday, February 12, 2009

The Hello World Applet

Editorial Note: I have removed some of the links on this page because the tutorial has been updated; the old links don't work, and the applet code has been changed since this blog entry was made.

So the "next" lesson in the trail is Getting Started with Applets. I hate hello world, but after the last lesson I'm quite pleased to see it. At least it provides a scrap of code to play with. If I can embed this applet into my web page, it will improve my understanding, and if it works, it will make me feel better. So to facilitate the process, I check out the source code for the page.

The first thing I notice is that the code calling the applet on this page is completely different to the example on the previous page. The example given was:

 <applet code=AppletWorld.class

width="200" height="200">

But the code used to call the Hello World applet is:

<applet code="HelloWorld.class"

="150" height="30">

That looks more like a jnlp file than the example Linkgiven, and it certainly makes it harder to copy and paste. The first question is why, if we need a jar file to run this applet, was it not mentioned on the all informative index page. And if there isn't room to tell the whole story on that page, why tell any part of it at all.

To test this, I'll compile Hello World from the source code given here, and try running it with the code given on the index page. I'll insert:

    <applet code="HelloWorld.class"

width="150" height="50">

To my amazement, it works, not only on my server but also on my ISP hosted page.

No comments: