What is applet?
Applet is a special Java program that cannot be run separately, need to be embedded in an HTML file, interpreting by browser or appletViewer
Execution .applet may be transferred through the network, and is automatically loaded and executed by the browser.
Unlike Applicaton, the Applet program must inherit the Java.applet.applet class from Java or javax.swing.japplet class
Public class myapplet extends java.applet.applet
or
Public class myapplet extends javax.swing.japplet
In fact, the JApplet class is also inheriting from the Applet class.
To browse the applet, you need to embed it in the web page, just insert the
<
Applet [
Codebase =
Applet's URL path]
Code =
Applet class name
Width =
Applet's width
HEIGHT =
APPLET's height [
Alt =
Text for replacement when you cannot display Applets]
[
Name =
AppleT name]
[
Align =
Alignment]
[
VSpace =
Vertical direction blank distance]
[
HSPACE =
Level direction blank distance]
>
<
PARAM
Name = parameter name
Value = Parameter Value>
Applet>
* The content in brackets is optional. Example:
// Import the singular name
IMPORT JAVA.Applet.applet;
// Import the base class
Import java.awt.graphics;
// Import graphics
// Main program class
Public Class FirstApplet Extends Applet
{
Public void Paint (Graphics G)
{
// Display text g.drawstring in the coordinate (30, 30) position ("this is the first applet", 30, 30);
}
}
Compiled as FirstApplet.java to Firstapplet.class
title>
hEAD>
h1>
Div
Align = center>
<
applet
Code = firstapplet.class
Width = 300
HEIGHT = 100>
Applet>
Div>
body> html>
Firstapplet.html
Place firstapplet.html and firstapplet.class on the same folder