About HPC Systems Software User Guides Education Partners

  / gears / hpc / education / tutorials / java


Introduction

Definition

Examples

Installation

Applets

Example 01

Example 02

Example 03

Example 04

Example 05

Example 06

Object Oriented Programming

Java Security

References

Applets


Development

  • APPLET NAME - applet1
  • PURPOSE - Write some text to a standard output

The table below shows the listing for an applet and the explanation of each line of code.

LISTING

EXPLANATION

import java.applet.Applet;

Similar to #include statement in c or c++. This statement pulls in the classes that are contained in the basic release named java.applet.Applet.

import java.awt.Graphics;

This pulls in the classes that are contained in the basic release named java.awt.Graphics (awt=applet window toolkit).

public class applet1 extends Applet {

This is a Class definition
The keyword extends indicate that this is a subclass of the Applet class; or, Applet is a superclass of HelloWorldApplet.

public void paint(Graphics g) {

The paint method is passed a Graphics object which we 've to call g.
also to explain paint
then Graphics g
that is all folks

g.drawString("Abdul H. Aziz!", 50, 25);

Within the paint method we call g's draw String method to draw the string "Abdul H. Aziz!" at the coordinated (50,25).
50 pixels across
25 pixels down

}

this is a synatax thing

}

this is a synatax thing

Compilation

An applet is a Java program that has an extension .java at the end (such as HelloWorldApplet.java). To compile a Java applet type:

javac HelloWorldApplet.java

UNIX

javac HelloWorldApplet.java

Window 95/NT

Drag the HelloWorldApplet.java file icon
onto Java Compiler icon

Macintosh

This will produce a binary file also called byte-code named HelloWorldApplet.class

Running

One of the following commands allow you to view an applet locally.

appletviewer HelloWorldApplet.html

UNIX

appletviewer HelloWorldApplet.html

Windows 95/NT

Start up the Applet Viewer

Macintosh

From the File menu, choose Open HelloWorldApplet.html

This will produce a window with the text "HelloWorld"

Embedding in html pages

<applet code="name.class" width=integer height=interger>


Please send questions or suggestions about this web page to beatnic@aset.psu.edu

ASET | ITS | Penn State