View Single Post
  #2 (permalink)  
Old 06-20-2007, 10:36 AM
Zia Zia is offline
Junior Member
 
Join Date: Apr 2007
Posts: 16
Default

First of all, there is a need to understand that the APPLET tag in an HTML document identifies the name of a Java program called an applet to be included in a Web page. The name of the applet is called its class name. This name is associated with the executable bytecodes that run the applet.

Now, let me provide you one example which will demonstrate you how to include an applet in a Web document. If you want to test this, put the following lines in a file called Hi.html:

<HTML>

<HEAD>

<TITLE>Hi My dear Hosting Friend</TITLE>

</HEAD>

<BODY>

<APPLET Code=”Hi.class” Width=”600" Height=”300">

</APPLET>

</BODY>

</HTML>

You can see in the example, there is an open APPLET tag, <APPLET>, and a close APPLET tag, </APPLET>. The attributes shown here are Code, to identify the class file which contains the Java bytecodes and the Width and Height attributes, measured in pixels, to describe how much room should be reserved on the Web page for the applet.
Let me provide you the general syntax of the APPLET TAG

<APPLET

Codebase = “path to directory containing class files”

Code = “name of class file”

Width = “width of applet in pixels”

Height = “height of applet in pixels”>

<PARAM Name=”parameter name” Value=”value of parameter”>

<PARAM Name=”parameter name” Value=”value of parameter”>

</APPLET>

here is a minimal Java applet that will help you:

import java.awt.Graphics;

/**

A first hello.

*/

public class Hi extends java.applet.Applet {

public void init() {

resize(600, 300);

}

public void paint(Graphics context) {

context.drawString(“Hello, world!”, 50, 100);

}

}

You can place Java code in a file named Hi.java. Next, you have to compile the Java source code using the Java compiler, javac. At the operating system prompt ($), enter:

$ javac Hi.java

If there are no errors, the compiler will create a file named HelloWorld.class that contains the bytecodes for the HelloWorld applet.

So at this point, you have the following:

* A file called Hi.html. This is the hypertext markup language (HTML) source file.
* A file called Hi.java. This is the Java language source file.
* A file called Hi.class. This is the Java bytecode file.

If you have a Java-enabled browser, you can test this applet. Use the browser to open the file HelloWorld.html. Alternatively, you can also use the applet viewer supplied with the Java Developer’s Kit (JDK) to view applets without having to make an HTML page to reference them.
Reply With Quote