Applet in Java- Basic Concepts

Applet in Java is used to create GUI based standalone Java programs. These can be embedded as GUI elements into the code like web applications or web pages.

Applet implement event driven programming. An Applet in Java waits for an event to occur and responds depending on what user has done. They run inside the web browser or Appletviewer. Appletviewer is a part of the JDK.

APPLET is used to deploy applets in anHTML file. AWT (Applet Window Toolkit) packages are used to handle events and draw objects and elements at the specific coordinates to create desired interface. Applets provides interactivity that misses in HTML pages. Applets provide ease of building applications with java as backend. Eclipse IDE is a highly versatile IDE to perform applet tasks.

Architecture of an Applet in Java

Architecture of applet is quite different than the standalone programs. Applet uses GUI elements for performing various actions from user.

Applet in Java

Skeleton of an Applet

Applet in Java Programming extends the Applet class. An applet uses features of AWT. In an applet program basic methods are overwritten. These methods are init(), start(), stop(), paint() and destroy(). Example of an overwritten skeleton program is given below:

import java.applet.*;
import java.awt.*;
public class Skeleton extends Applet{
	public void init(){
	}
	public void start(){
	}
	public void paint(Graphics gs){
		gs.drawString("Hello and welcome to this applet window!", 20,45);
	}
	public void stop(){
	}
	public void destroy(){
	}	
}

Advanced applets can also be created by writing complex logic inside the methods defined in the above code.

Status Window

The status window is used to display information regarding the ongoing events in the output. It can be called by using the showStatus() method that is predefined in AWT. In most of the cases the status window displays the current status or debugging information to the user.

showStatus(“Applet is running”);

HTML APPLET Tag

APPLET tag is used to deploy applet directly through an HTML file. Whenever a APPLET tag is encountered by the web browser, the applet is executed by the browser itself. Multiple applets can also be implied in a single HTML document. Some of the crucial attributes are WIDTH, HEIGHT, NAME, CODE, CODEBASE and so on. Example of the APPLET tag with syntax is given below:

<APPLET 
	CODEBASE= "<!—URL of the code directory—>"
	CODE="ExamForm.class"
	align="left" 
	height="500" 
	width="400"
	ALT="Applet1"
	HSPACE="10"
>
<PARAM NAME=AttributeName VALUE="">
 </APPLET>

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *