Applets are small applications that are accessed on an Internet Server, transported Internet, automatically installed, and run as part of a Web document.

Applet is a program written in Java and included or embedded in an HTML page. An applet is automatically loaded and executed when you open a web page that has the applet. The applet runs in a web page that is loaded in a web browser. The life cycle of an applet is implemented using methods, init(), start(), stop(), and destroy().

Once an applet arrives on the client, it has limited access to resources, so that it can produce an arbitrary multimedia user interface and run complex computations.

A sample applet:

import java.awt.*;
import java.applet.*;

public class SimpleApplet extends Applet {

     public void paint(Graphics g){

          g.drawString("Hello World", 20,20);
     }
}

Applet begins with two import statements

sincerelibran explained it very well though so there is not much left to say but I'll say it anyway.

When you run the applet code in java, it asks for a height and width then it runs your program. But after you entered the height and width, it automaticly made a HTML file where the applet was saved.

That HTML file is your applet you just executed. With this HTML, you can embed it into a web page for people to view and play online!

The applet snippet above draws "Hello World!" onto the screen at x coordinate 20 and y coordinate 20. To use the "public void paint(Graphics g)" you MUST import the java.awt.*; for the graphics to work.

Also (from past experience) the graphics class get draw right after the init class so any buttons or textfields will not be shown, but they are there. (just painted over).
Also you must import java.applet.*; to make the applet.

I hope that this answers your question.

javanoob101

This article has been dead for over six months. Start a new discussion instead.