Consider the following applet:
// A first applet in Java import javax.swing.JApplet; // import class JApplet import java.awt.Graphics; // import class Graphics public class WelcomeApplet extends JApplet { public void paint( Graphics g ) { g.drawString( "Welcome to Java Programming!", 25, 25 ); } } |
To use the appletviewer
utility to run applets, you
need to create a short html file with an applet tag, as shown in
the example below (WelcomeApplet.html
):
<html> <applet code="WelcomeApplet.class" width=300 height=30> </applet> </html> |
The appletviewer can be run from the command line:
appletviewer WelcomeApplet.html
The results are shown below:
To use Java Plug-in to run applets on web pages, you need to convert applet tags on those web pages to object tags. An example of the required HTML code is shown below. The fields in blue show values that would typically be changed by the user.
For general information see Java Plug-in Technology.
<OBJECT classid="clsid:CAFEEFAC-0014-0001-0002-ABCDEFFEDCBA" width="300" height="30" align="baseline" codebase="http://java.sun.com/products/plugin/autodl/jinstall-1_4_0_02-windows-i586.cab"> <PARAM NAME="code" VALUE="WelcomeApplet.class"> <PARAM NAME="type" VALUE="application/x-java-applet;version=1.4.1_02"> <PARAM NAME="scriptable" VALUE="true"> No Java 2 SDK, Standard Edition v 1.4.1_02 support for APPLET!! </OBJECT> |
For more information see Using object and applet tags in the Java Plug-in.
The WelcomeApplet example should be running below:
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" width="300" height="30" align="baseline" codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0"> <PARAM NAME="code" VALUE="WelcomeApplet.class"> <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3"> <PARAM NAME="scriptable" VALUE="true"> No Java 2 SDK, Standard Edition v 1.3 support for APPLET!! </OBJECT> |
For more information see the Java Plug-in HTML Specification.
Maintained by John Loomis, last updated 21 May 2001