Java Applet programming

The Abstract Window Toolkit (AWT) is a set of Java classes that allow the programmer to create a Graphical User Interface (GUI) and accept user input through the keyboard and the mouse.

Java Applet programming

They are heavyweight components of Java Foundation Classes (JFC). The java.awt package contains all classes for creating user interfaces and for painting graphics and images.
The AWT has several subsystems that support the development and creation of an attractive and efficient GUI. The subsystems include:

  • Containers
  • Components
  • Layout managers
  • Graphics and drawing capabilities
  • Fonts
  • Events

An Applet is a Java program that can be embedded in an HTML page and executed on a Java enabled browser.

Difference between Applets and Applications

An Applet is basically designed for deploying on the web.
An application is designed to work as a standalone program.

Applets are created by extending the java.applet.Applet class.
There is no such constraint for an application.

Applets run on any browser.
Applications run using Java interpreter.

Execution of Applets begins with the init() method.
Execution of applications begins with main() method.

Applet must contain at least one public class failing which the compiler reports an error. It is not mandatory to declare main() for an applet.
In case of application, main() has to be included in a public class.

Output to an Applet’s window is done by using different AWT methods such as drawString().
In case of an application System.out.println() method is used.

Life cycle of an Applet 

Life cycle of an object specifies stages, which the object has to pass right from its creation until it is destroyed.
An Applet defines its structure from four events that take place during execution.
For each event, a method is automatically called.

The methods are as follows:

init(): called during initialization.
start(): starts the Applet once it is initialized.
stop(): used to pause the execution of an Applet.
destroy(): used to destroy the Applet.
paint():used to display a line, text or an image on the screen.
repaint() : used to paint the Applet again after it has been drawn once.