Entry
Java: Applet: Create: Simple: How to create a Java applet that displays 'Hello World'?
Sep 6th, 2003 16:26
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 07 September 2003 - 01:09 am ------------------
Java: Create: Applet: Simple: How to create a Java applet that
displays 'Hello World'?
---
In general:
---
Download and install the latest Java developer kit e.g. at
http://java.sun.com/getjava/download.html
or
http://www.sun.com
---
When creating a Java program, each Java program will usually always
mean the creation of at least 3 files:
1. .java text file
2. .class file
3. .html (or .htm) file
---
Steps: Overview
1. Create the Java source file
1. Create a .java text file in your favorite editor,
2. Save it e.g. as 'HelloWorldApplet.java'
2. Compile it using the Java compiler
1. e.g. type the command on the command line:
javac c:\HelloWorldApplet.java
(this javac.exe usually can be found in the 'bin' directory
of your Java installation)
2. This will generate (after possible debugging) a file
with the extension .class, so here:
c:\HelloWorldApplet.class
3. Create the HTML file
1. create the following file in your favorite editor
2. and save it as 'HelloWorldApplet.html'
4. View the result
1. By using your browser:
-type the URL:
c:\HelloWorldApplet.html
2. By using SUN's appletviewer
-type the command on the command line:
appletviewer c:\HelloWorldApplet.html
PS Make sure that you adapt this to the path of your files.
---
Steps: Worked out:
How to create an Java applet that displays 'Hello World'?
1. Create the following file in your favorite editor, and save it
as 'c:\HelloWorldApplet.java'
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorldApplet extends Applet {
public void paint( Graphics g ) {
g. drawString( "Hello world!", 50, 25 );
}
}
2. Compile it using:
javac c:\HelloWorldApplet.java
This will generate, after possible debugging the file
c:\HelloWorldApplet.class
3. Create the following file in your favorite editor, and save it as
'c:\HelloWorldApplet.html':
<HTML>
<HEAD>
<TITLE>
Hello World
</TITLE>
<BODY>
This is the applet :<P>
<APPLET
CODE = "HelloWorldApplet.class"
WIDTH = "150"
HEIGHT = "50"
>
</APPLET>
</BODY>
</HTML>
4. Open your browser, and run this file by typing the URL:
c:\HelloWorldApplet.html
5. This should show the text 'Hello world' in the rectangle
in your browser screen.
----------------------------------------------------------------------