- In a web page (HTML file), use the <applet>...</applet>
tags. Attributes:
- code=classfilename.class
- width=applet_width
- height=applet_height
- archive=archivefile - for loading an archive
file with multiple classes, like a jar file
- codebase=url - to specify that the applet code is in
a different location than this html file
- vspace=verticalmargin
- hspace=horizontalmargin
- align=alignmentvalue
- alt=alternate_text - what to print if applet cannot
display
- To pass parameters into the applet, use the html <param>
tag, which goes between the <applet>...</applet> tags.
Each parameter has a name and a value -- the syntax is:
<param name=parametername value=parametervalue>
Examples:
<param name=X value=100>
<param name=LASTNAME value="Smith">
- In the program, to read a parameter, use the following Applet class
method:
public String getParameter("parametername");
Sample usage, given above param tag examples (from inside applet):
int x = Integer.parseInt(getParameter("X")); // stores 100 in x
String last = getParameter("LASTNAME"); // stores "Smith" in last
- A few examples of applet tags:
<applet code="Welcome.class" width="350" height="175"></applet>
<applet code="Thing.class" archive="myThings.jar"></applet>
<applet code="StartGame.class" archive="game.jar">
<param name=numPlayers value=2>
</applet>