|
Java
Applets & |
PAGE (3 of 7) |
![]()
Java applets must first be compiled before running. You may download the Java Development Kit (JDK) at http://java.sun.com/products/jdk. Or you may already have access to the Microsoft J++ Developer. Either will do.
The JDK provides a compiler you can use to compile all kinds of Java programs. It also provides an interpreter you can use to run Java applications. To run Java applets, you can use the JDK Applet Viewer or any Java-compatible Web browser. Alternatively you may elect to download the Java Runtime Environment, (also known as the Java Runtime or JRE), which will allow you to run Java applets outside of a browser.
Once an applet is compiled, it can be run on a Java-compatible, Java-enabled browser, (or in the JRE). Such compatible browsers are Netscape Navigator 2.0, the Microsoft Internet Explorer 3.0, and all later versions from both companies. For a browser to be Java-enabled, it must be specified to run Java applications by setting the security permissions within the browsers options (consult your browser's Help files to find out how to do this within your own browser).
Create an HTML File that Includes the Applet
|
<HTML>
<HEAD>
<TITLE> A Sample Applet </TITLE>
</HEAD>
<BODY>
....... document text here ........
<APPLET CODE="applet_name.class" WIDTH=integer_value
HEIGHT=integer_value>
</APPLET>
</BODY>
</HTML>
|
For an applet to run within an HTML page, it must be specified within the <APPLET></APPLET> tags.
Here's the simplest form of the <APPLET> tag:
<APPLET CODE=myApplet.class WIDTH=anInt HEIGHT=anInt>
</APPLET>
This tag informs the browser to load the applet, named myApplet, from the same directory as the current HTML document. The width and height are specfied to reserve a display area in pixels for the applet.
The codebase property designates the absolute or relative URL or subdirectory for the applet. This allows an applet to be run from remote sites. Its syntax looks like:
<APPLET CODE=applet_name.class CODEBASE=someURLorDIRECTORY WIDTH=integer_value HEIGHT=integer_value>
</APPLET>
The <PARAM> tags must appear between the <APPLET> and </APPLET> tags for the applet they affect. Its syntax:
<APPLET CODE=applet_name.class WIDTH=integer_value HEIGHT=integer_value>
<PARAM NAME=parameter1 VALUE=value1>
<PARAM NAME=parameter2 VALUE=value2>
</APPLET>
Types of parameters:
<PARAM NAME=windowType VALUE="BorderWindow">
<PARAM NAME=windowText VALUE="BorderLayout">
<PARAM NAME=buttonText VALUE="Click here">
The <PARAM> tag allows you to provide arguments to a Java applet to control its behavior. PARAM arguments must occur as NAME and VALUE pairs. The programmer of the applet supplies documentation on these arguments and retrieves the PARAMeters during applet execution.
Alternate HTML code for those readers using browsers that aren't Java-enabled is any text between <APPLET> and </APPLET> tags, except for <PARAM> tags. This code does not affect Java-enabled browsers.
|
© CS Dept Va Tech, 1997-1998. |
All rights reserved. |