Applets

Putting an Applet on a Web Page

<html>
<head>
<title>An Applet Example</title>
</head>
<body>
<p>The Applet example is: <br>
<applet code="MyApplet.class" width="200" height="50">
<param name="font" value="TimesRoman">
<param name="size" value="16">
You see this if your browser does not include Java support.
</applet>
</p>
</body>
</html>

If the OBJECT tag is used rather than the APPLET tag, use CLASSID in place of CODE to specify the file name. A JAR (JAVA Archive) file is a package of the applet (or application) along with all required supporting class files. The "jar" command is used to create these JAR files from class and gif files.


Applet Attributes

The APPLET element is depreciated in favor of the OBJECT element for those browsers that support it. The OBJECT element is described below.

  • ALT - Alternate text if the applet is not loadable.
  • CLASS="..." - The name of the applet.
  • CODE - The name of the applet main class file.
  • CODEBASE - Specifies a different folder for the browser to look for the applet file.
  • WIDTH - The width of the applet output area in pixels.
  • HEIGHT - The height of the applet output area in pixels.
  • ALIGN - ALIGN="TOP "- Indicates how the applet should be aligned with any text that follows it. Values:
    • LEFT
    • RIGHT
    • TOP - Align with the topmost item in the line.
    • BOTTOM
    • MIDDLE
    • ABSMIDDLE
    • ABSBOTTOM
    • BASELINE
    • TEXTTOP
  • PARAM - Used to pass parameters to applets. Parameters expected but not passed are passed as a NULL. Your program needs to test for NULL parameters and set a default for any expected parameters. The "getParameter" function is used to get the passed parameters in the applet.
  • SRC="..." - The URL of the directory where the compiled applet can be found (should end in a slash / as in "http://mysite/myapplets/"). Do not include the actual applet name, which is specified with the CLASS attribute.
  • HSPACE - Space in pixels between the applet and the text around it.
  • VSPACE - Vertical space between the applet and other text.




The Object Element

Example

<html>
<head>
<title>An Applet Example</title>
</head>
<body>
<p>The Applet example is: <br>
<object classid="java:MyApplet.class" codetype="application/java" width="200" height="50">
<param name="font" value="TimesRoman">
<param name="size" value="16">
You see this if your browser does not include Java support.
</applet>
</p>
</body>
</html>

Object Attributes

  • ALIGN - (Depreciated) - Sets alignment to middle, top, bottom, left, or right.
  • ARCHIVE - Lets the browser download several archive files at once.
  • BORDER - (Depreciated) - The width of the border.
  • CLASSID - Determines how the object is implemented.
  • CODEBASE - Sets relative URI locations.
  • CODETYPE - Specifies whether it is an application and program language.
  • DATA - The embedded object Universal Resource Indicator (URI).
  • DECLARE - The object is not instantiated until a link is later clicked on or an object uses it.
  • HEIGHT
  • NAME
  • STANDBY - Text to be displayed while the object is loading.
  • TABINDEX - A numerical value that sets the tabbing order of the object.
  • TYPE - Sets the media type such as screen, printer, TV.
  • USEMAP

See the "Recommended Reading" section for sources of a more complete list.


The PARAM Element

Used to set up parameters for the OBJECT and APPLET elements. (Occurs inside <applet> or <object> tags.) There is no ending tag for this element. Attributes include:

  • NAME="..." - The type of information being given to the applet or ActiveX control.
  • TYPE - The MIME content type of the resource.
  • VALUE="..." - The actual information to be given to the applet or ActiveX control.
  • VALUETYPE - Sets the type for the VALUE attribute. Possible values include data, ref, and object.