[an error occurred while processing this directive] Using Java Applets with WebCom Introduction - What is Java?

Java, in short, is an object-oriented programming language developed by Sun Microsystems. Java can be used to write programs, commonly referred to as "applets", which can actually be inserted into a Web page. An applet can do just about anything that can normally be accomplished by writing software applications. Applets are most commonly designed to display animations, play sounds, draw dynamic interactive graphics, play games, and present usable spreadsheets online.

Java applets do not, however, automatically work with all browsers. Only browsers which are specifically designed to be Java-compatible will execute Java code correctly. Such browsers include the latest versions of Netscape Navigator and Microsoft Internet Explorer (may not be supported on all platforms).

Programming in Java

It is generally agreed upon that a background in C++ programming makes learning Java relatively easy. Otherwise, learning to program in Java will involve considerable time and energy. If you are interested in programming your own Java applets, a good place to start is Sun's Java Web Site, where you will find extensive technical information concerning Java, along with a Java tutorial.

Adding Applets to your Web Pages

For those Web designers who do not wish to learn to program in Java, pre-designed Java applets can be acquired from commercial or freely available Java archives and configured to work with your WebCom site. An applet is made up of the basic program (a file or files ending in .class) and any auxiliary sound, graphic, or data files used by the applet. Once you have these files placed in the appropriate places (more on this below), you then need to insert the proper HTML tags in your Web page to call and run the applet.

Anatomy of an Applet Reference

The basic syntax of the HTML tags used to launch a Java applet is shown below. You can click on any of the hotlinked elements to see a more detailed explanation of each.

<applet code=Filename.class
height=number
width=number
codebase=Directory_containing_applet
align=setting
hspace=number
vspace=number
name=string>

<!-- Set multiple parameters to specify configurable options for the applet -->
<param name=name1 value=value1>
<param name=name2 value=value2>
<!-- Number of params determined by the nature of the applet -->

<!-- Define alternate content, to be shown by non-Java browsers -->
<H2>Imagine you are seeing impressive Java applet here</H2>

</applet>

An example of the HTML tags used to launch a Java applet from within an web page would be:

<applet code=ScrollingNeonMessage.class height=200 width=400 codebase=applets>
<param name=MessageText value="Bookmark this page!">
<param name=ScrollSpeed value=10>

<H2>Bookmark This Page!</H2>

</applet>

Let us examine the above call to this theoretical applet. The first tag has several elements. The first, code=ScrollingNeonMessage.class, tells the browser that the java file to run is ScrollingNeonMessage.class. The next two elements, height=200 and width=400 define the dimensions of the box in which the applet will appear. The last element in the opening applet tag, codebase=applets, is optional, and tells the browser that the Java "executable" file (ScrollingNeonMessage.class) can be found in a subdiretory of the current directory, named applets.

Next, there are two parameters which need to be defined for this particular applet to work. The number and types of parameters will vary from applet to applet, and some applets do not require parameters at all. In this case, the parameter tags, <param name=MessageText value="Bookmark this page!"> and <param name=ScrollSpeed value=10>, tell the applet to scroll the message "Bookmark this page!", at a speed of 10 pixels per second.

Following the parameter definition tags, you then have the opportunity to specify alternate HTML which is to be displayed by non-Java capable browsers. As you see in this example, we will have such browsers simply display the same message in level 3 heading format: <H2>Bookmark This Page!</H2>.

After the alternate HTML has been given, all that is left to do is end the applet definition section, with </applet>.

Online Java Resources [an error occurred while processing this directive]