Go Back   CP Web Hosting - reseller hosting > Server Scripting > Java/JSP/J2EE
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-20-2007, 09:22 AM
zen zen is offline
Junior Member
 
Join Date: Apr 2007
Posts: 7
Default Where to put the <APPLET> Tag

Hi,

I am not able to understand where to put the <APPLET> tag in the HTML file. Can anybody please, help me in this regard?
Reply With Quote
  #2 (permalink)  
Old 06-20-2007, 09: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
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 08:01 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0