0  0 2016-10-28 11:11:12

An applet is a special Kind of java program that is primarily used in Internet Computing.
It can be transported from one computer to another on internet and run using the applet viewer or any java capable web browser such as Hot Java or Netscape.
We can embed applets into Web pages in two ways:
1. Local Applets:
We can create our applets by own design and embed them into web pages.
Since it is developed locally as well as store locally, this is local applets. Obviously when we create it locally we can use the internet and therefore we cannot require internet connection.

2. Remote Applet:
We can download available applet from remote computer system and then embed it into web page. This is remote applet.
This kind of applet can be created by someone else and stored on the remote machine. So to access them we require internet connection. Without internet connection. We cannot work with remote applets.
Advantage of Applets:
• Java applets ensure security and prevent the software from being affected by viruses.
• Java applets are useful to include something dynamic in the display of a web page.
• Java applets are used to give “flash” outputs. Ex. Applets that produce sounds, animations or some special effects.

Developing Applets:
 Steps for develop and testing:
 Building an applet code (.java file)
 Creating an executable applet (compile to create .class file)
 Designing a web page using HTML tags
 Preparing <APPLET> tag
 Incorporating <APPLET> tag into the web page
 Creating HTML file
 Testing the applet file

Simple Applet Programme:
import java.awt.*;
import java.awt.*;
public class Welcome extends Applet
    public void paint(Graphics g)
        g.drawString(“Welcome to the world of Applets”, 40,50);

1. Save the above programme as
2.Compile to create class file
3. javac
4. write the below html tags in another  file

        <APPLET CODE=Welcome.class HEIGHT=200 WIDTH=250>

1. Save the file as Welcome.html
2. Run
>appletviewer Welcome.html

OUTPUT: Welcome to the world of Applets!

Passing Parameters to an Applet:
To pass parameters to an applet, two things are required - a special parameter tag in the HTML file and the code in the applet to pass those parameters.
The special parameter tag in the HTML file is <PARAM>. This takes two attributes- NAME and VALUE
The init() method of the applet contains a method called getparameter().This method takes an arguments –the string. This represents the same of that parameter and returns a string containing the value of that parameter.
An applet illustrating the usage of passing parameters:

Import java.awt.*;
Import java.applet.*;
public class ParamTest extends Applet
    Font f=new Font(“TimesRoman”,Font.BOLD,20);
    String str;
    public void init()
        str=getParameter(“string”) ;
        str=”Hello” +str;
    public void paint(Graphics g)

1. Save the above code as
2. Compile to create class file
 java.c
3. Write the below html tags in another file.
        <APPLET CODE=ParamTest.class HEIGHT=200 WIDTH=200>

1. Save the html code as ParamTest.html
2. Run
 Appletviewer ParamTest.html

OUTPUT: HELLO my friend

Comments (0)

Post Your Comments


Hong Kong Office

Find Us On

Website Development Company
Digital Marketing
website development company in Hong Kong
website designer in pune