Home Applet Index SlideShows Nova Applets JavaScript Perl Software Purchase
Hot Tools
PopUp Maker code generator, CodeLifter page-code ripper, Scrollbar Styler, more... tons of *free* JavaScript!
Click Here!
Help: Java: Applet Basics

It Isn't That Difficult...

.
Setting up JAVA applets, though perhaps daunting the first time you do it, is really quite simple.  There are only two types of HTML tags required - both easy to deal with.

The APPLET tag basically just tells the browser what applet.class file to use, and how wide and high the applet should be.  (There are additional attributes you can set up, too; but in simplest use, that's all there is to this tag.)

The PARAM tag is likewise simple -- it Names a parameter the JAVA applet needs to run, and provides a Value for that parameter.  Though a given applet may have anywhere from no PARAM tags to dozens, still, every PARAM tag takes the very same simple form: just a Name, and a Value.

In addition to the tables outlining the APPLET tag, Positioning elements you can use with it, and the PARAM tag, there's also a simple EXAMPLE below, explained in basic terms.

(All CodeBrain applets also come with ample demos, pre-made HTML, and detailed 'cheat sheet' instructions.  Most better providers of applets do similarly.)

And please, remember the CodeBrain maxim:  "This is simple -- don't make it complicated!"

=O=


The <APPLET> </APPLET> Tag
Okay, we know this looks like a nightmare waiting to happen... but guess what:  Most of what you see in the table below is very rarely used.  The basic use of this tag looks like this:

<APPLET CODE="SomeApplet.class" width="300" height="200">
...
parameters -- see example below
...
</APPLET>

Simple enough, eh? Still, take a few minutes to run through the table below.  Though only Code, Width, and Height are generally needed, you should at least have an awareness of the rest.

Note that applet tags aren't case sensitive, by the way... but links and calls to resources like image files or sound files, etc., absolutely are!

Attribute Description Usage Required?
Code Name of
applet .class file
Code="Applet.class" Y E S
Width Width of applet,
in pixels
Width = 300 Y E S
Height Height of applet,
in pixels
Height = 150 Y E S
Codebase Path to directory where applet resides; also resources Codebase="applets /"
(that is, a path)
ONLY if the .class file is in a directory other than that of the HTML page
Alt Text displayed in browsers that do not support JAVA, or have JAVA disabled alt = "Your browser does  not support JAVA" NO - virtually all browsers in common use now support JAVA; though some users turn it off
Name Applet name Name="George" ONLY in special cases, usually with applets made to communicate with each other or with JavaScript
Align
Positions applet in relation to images and/or text around it, using:

Left, Right, Top, Texttop,Middle, Absmiddle, Baseline, Bottom, Absbottom

Align=Right NO -- but these often neglected attributes are extremely helpful in layout
Vspace Vertical space, in pixels, above and below applet Vspace =10 NO -- but helpful in layout
Hspace Horizontal space, in pixels, to left and right of applet Hspace=40 NO -- but helpful in layout
Notes...

Especially for newcomers to JAVA, it's best to put ALL files related to the applet -- the .class file, any associated images, text files, and the HTML page -- in the SAME directory.

Do NOT use Codebase= when setting up an applet. Get the Applet working FIRST -- then worry about organizational concerns.

Bad pathing -- meaning the HTML page can't find the applet, or the applet can't find the files it needs -- is one pf the most common reasons for difficulty in setting up JAVA applets!

=O=


The <PARAM> Tag
Attribute Description Usage Required?
NAME Name of the Parameter PARAM="WhateverName"

PARAM's vary broadly from applet to applet, depending on the requirements of the individual applet.  PARAM's are absolutely NOT standard, like HTML tags, so *read* the documentation with every applet!

Y E S
VALUE The Value associated with the Parameter VALUE=100
or
VALUE="Image.gif
etc.

VALUE's vary from applet to applet, depending on the requirements of the individual applet.  VALUE variables are absolutely NOT standard, like HTML tags, so *read* the documentation with every applet!

Y E S
Notes...

Virtually all applets have one or more parameters -- but it is possible to have an applet that has none.

The NAME of each PARAM will be different.  Take special care to spell and case the NAME exactly -- typos in parameter names (and values) are the second most frequent cause of difficulty in setting up applets.

Some VALUE attributes will take multiple values, for instance:
<PARAM NAME="BackgroundColor" VALUE="255,126,32">
Be careful to include the commas, and never leave spaces!

Note that unlike most HTML tags, the PARAM tag stands alone, and does NOT use a </param> closing tag.

=O=


Positioning Elements - Optional
Positioning elements are entirely optional.  If you're a newcomer to JAVA, you can, indeed, ignore them.  Still, they can get you out of various calamities in layouts, so it's a good idea to at least know they exist.

The positioning elements go into the <APPLET> tag, like this...

<APPLET CODE="SomeApplet.class" WIDTH="300" HEIGHT="200" ALIGN="left">
...
parameters -- see example below
...
</APPLET>

You might keep in mind that the positioning elements are especially useful when working with tables and background graphics.

Attribute Description
default aligns applet using default browser settings -- same as baseline
left aligns applet to left margin and wraps text that follows the applet
right aligns applet to the right margin and wraps text that precedes the applet
top aligns top of applet with the surrounding text
texttop aligns top of the applet with the top of tallest text in the line
middle aligns middle of applet with surrounding text
absmiddle aligns applet with middle of the current line
baseline aligns applet with baseline of current line
bottom aligns bottom of applet with surrounding text
absbottom aligns applet with bottom of the current line
center aligns center of applet with surrounding text

=O=


Simple Example
.
<HTML>
<BODY>

<APPLET CODE="CodeBrainSlider.class" WIDTH="360" HEIGHT="150">
.....<PARAM NAME="BackgroundColor" value="255,0,0">
.....<PARAM NAME="Image1" VALUE="greendog.jpg">
.....<PARAM NAME="Image2" VALUE="redpig.jpg">
</APPLET>
.
</BODY>
</HTML>

.
Translation...
.
What the above HTML code actually says, is:  Call the JAVA applet named CodeBrainSlider.class.   Make it 360 pixels wide and 150 pixels high.  Make the BackgroundColor rgb 255,0,0 (that's red).  For the first image in the applet, use the file called greendog.jpg, and for the second one use redpig.jpg.

=O=


.


CodeBrain.com
- Copyright 1995-2014 by CodeBrain.com
CodeBrainŽ CodeBrain.comŽ
All  Rights Reserved

.
A wise man eats both with his mouth and with his shoes.
Four candles do not make the camel sing.


.