' How to Make and Run a Java Applet Program Using Applet Viewer or Web Browser | Infolet

How to Make and Run a Java Applet Program Using Applet Viewer or Web Browser

Creating and running a java applet using applet viewer

   An applet is a small application designed to be transmitted over the Internet and executed by a Java-compatible Web browser. Applets are event driven programs. Java applet programs are different from java application programs. Click to Learn how to build and run a java application program. 
Now let us see how to build and run a Java applet program.

►Open any text editor like notepad and type below code to print ‘Hello’ as an applet.
Make and Run a Java Applet Program
♦A = imported for applet programs. 
♦B = AWT is stands for Abstract Window Toolkit.Contains many tool pack like graphics. 
♦C = Paint function is to perform different graphics activities. 
♦D = to print a string. 
♦E = String you want to print. 
♦F = X coordinate of your string in applet window. 
♦G = Y coordinate of your string in applet window. 
♦H = ‘test’ is your class name is must be equal to your program name. 

►Now save your file with .java extension. (Program name must be equal to class name)
►Compile your java program. (Same as compiling of java application program)
[Learn How to save a file with .java extension and compiling a java application program.]

Method to run a Java applet program is not similar to method to run a java application program.
There are two methods to run a Java applet program.
    ♦ Using Java compatible web browser
    ♦ Using Applet Viewer included with your JDK. 

Using Java compatible web browser

► Open any text editor like notepad.
► Type below code
<applet code = "test" width = 400 height = 300> </applet>
[Here width is the width of your output applet window and height is the height of your output applet window.]
►Save as a .html file in location of your java file.
     ♦If you want to save your html file in different location,
        Change above code to:
<applet code = "your location\test" width = 400 height = 300> </applet>
<applet code = "D:\my java files\test" width = 400 height = 300> </applet>
► After successful save, open your html file with any Java compatible web browser.
► Now you can see your applet in that browser.
Make and Run a Java Applet Program
If your browser is not compatible with Java, download java form here.

Using Applet Viewer

► Normally your JDK already contain an Applet Viewer for viewing applets (Search in your jdk folder).
► For using this method, add this line of code to your java program just before of your class.
/* <applet code = "test" width = 300 height = 300> </applet> */
► Now, totally your program should be like this:

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

 /* <applet code = "test" width = 300 height = 300> </applet> */

public class test extends Applet
 public void paint(Graphics g)
► Save again.
► Compile your Program.
► After successful compilation,  type:  appletviewer test.java  to run your applet.
Make and Run a Java Applet Program
► Now you can see output applet in Java Applet Viewer.
Make and Run a Java Applet Program

For any assist, comment below...


15 Respones to "How to Make and Run a Java Applet Program Using Applet Viewer or Web Browser"

Aslam Pk said...

What output you want?

March 26, 2013 at 6:21 PM
Agbaka New said...

I need help with a GUI apllet test, programm is written but cant seem to execute, please help

July 31, 2013 at 4:18 AM
Akanksha Jadhav said...

program is compiled after cmd appletviewer prgname.java
its showing applet not initialzed

January 30, 2014 at 7:55 PM
sharif said...

i have written this program in notepad.now, where can i compile this before running in applet viewer?

March 24, 2014 at 10:51 AM
SOFL said...

hai i written a applet program then compile it there was no error but wen i run appletviewer it was not coming.what is the problem

June 7, 2014 at 7:21 AM
Aslam Kakkove said...

There should be an error while running. Check. Or give me the code

June 7, 2014 at 10:13 AM
Keerthi Lucky said...

Thanks for the clear explanation!

June 19, 2014 at 11:36 AM
dinesh rak said...

thks its realy useful..i got output

October 21, 2014 at 7:38 AM
Hammami Hayet said...
This comment has been removed by the author.
Aslam Kakkove said...

create a button and set action listener.. then write codes for calling applet on button onclick event

November 17, 2014 at 10:54 PM

Post a Comment


Free Updates

Enter your email address:

Delivered by FeedBurner

Learn C

About Author

Author of infolet.org
Muhammed Aslam PK, He is a MCA(Master of Computer Applications) student. See More here
Contact Us
Return to top of page Copyright © 2010 | Infolet.org Google Converted into Blogger Template by HackTutors