Home Java Java-introduction Javatools The Java Applet Viewer
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

The Java Applet Viewer

Advertisement
Applet viewer is a command line program to run Java applets. It is included in the SDK. It helps you to test an applet before you run it in a browser.

The Java Applet Viewer

     

Applet viewer is a command line program to run Java applets. It is included in the SDK. It helps you to test an applet before you run it in a browser. Before going any further, lets see what an applet is?

An applet is a special type of application that's included as a part of an HTML page and can be stored in a web page and run within a web browser. The applet's code gets transferred to the system and then the Java Virtual Machine (JVM) of the browser executes that code and displays the output.. So for running the applet,  the browser should be Java enabled. To create an applet, we need to define a class that inherits the Applet.

We generally use web browsers to run applets. Its not always mandatory to open a Web browser for running an applet. There is another way as well. The other way to run an applet is through Java applet viewer. This is a tool that acts as a test bed for Java applets. The working of Applet viewer is a bit different from a Web browser, though they are logically same. The Applet viewer runs on the HTML documentation, and uses embedded applet tags. The difference in using the applet viewer and the web browser to run the applet is that the applet viewer only deals with the applet code not the HTML cod i.e. it doesn't display HTML code. So we should test our program in applet viewer and web browser to confirm its working.

The applet viewer command connects to the documents or resources designated by urls. It displays each applet referenced by the documents in its own window.

The syntax for the applet viewer is:

appletviewer Options URL 

Where the URL specifies the location of the applet program and the Options argument specifies how to run the Java applet. We can use only one option -debug that starts the applet viewer in the Java debugger. Using this option we can debug an applet.

The following program shows how to build an applet and the HTML file for it. Firstly create a class. Then start the applet using init method. After that enter a string as str = "This is my first applet". Use paint method to give the dimensions of the applet. Beneath that is the HTML file which shows how to give the body for applet.

Here is the Java File:

import java.applet.*;
import java.awt.*;
public class Myapplet extends Applet{
	String str;
	public void init(){
		str = "This is my first applet";
	}
	public void paint(Graphics g){
		g.drawString(str, 50,50);
	}
}

Here is the HTML File:

<HTML>
<BODY>
<applet code="Myapplet",height="200" width="200">
</applet>
</BODY>
</HTML>

After building the program, run the applet and the applet viewer as shown below.

C:\javac> javac Myapplet.java

C:\javac>appletviewer Myapplet.html

When we run the applet viewer it will display the window as shown below.


Back to Java Introduction

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 26, 2008

Ask Questions?    Discuss: The Java Applet Viewer   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
pankaj
March 29, 2011
Run the applet program

who to run the applet the program
abdul naser
April 8, 2011
thanx a lot!

thank u very much... it helped me...
vanita
June 22, 2011
java applet

know about java applet programs
Jasim kuttiyil
July 29, 2011
passin argument in applet

how to pass a double type variable to paint function from the init function. string variable is possible.. my question is double variable is possible or not... replay me
Rukayat Oseni
June 12, 2013
How to view java applet on Applet viewer

I have not try to run it cause i'm using my friend system to check for the solution to my problem.I strongly blieve that is going to work. Thanks a bunch!i'm also lookn forward to be a better java developer after this self training Insha Allahu!
burhanudin
August 29, 2011
comment

thank you,this is help me so
harshavardhan
September 22, 2011
thanks

hi dude thanks a lot after 1hr trying with various methods u'r is the only one which worked...thanku
Omprakash
December 11, 2011
java

How to run awt class program? how to create butto in java?
ganesh
January 28, 2012
java

good site for computer
sheela
January 10, 2013
question

hai sir, i want calculate used in applet viewer program, pls send my email.........
vivek
January 19, 2013
RMI

is there someone ,who can guide me through the RMI program and help me in showing the how it runs.... thanks
Muhammad Fayyaz
February 14, 2012
programming

for good internet programming
Muhammad Fayyaz
February 14, 2012
computer Science

for better programming on internet
Arindam
February 27, 2012
Error in appletviewer

When i use javac the applet gets compiled without any error but when I run the appletviewer BlanksApplet.html I get error applet not initialized but it runs in google chrome.my code is like this: import java.awt.*; public class BlanksApplet extends javax.swing.JApplet { String parameter1; String parameter2; String parameter3; public void init() { parameter1 = getParameter("adjective1"); parameter2 = getParameter("adjective2"); parameter3 = getParameter("adjective3"); } public void paint(Graphics s) { s.drawString("The " + parameter1 + " " + parameter2 + " fox " + "jumped over the " + parameter3 + " dog.", 5, 50); } } for the .java part and for the .html part I am using this code: <applet code =" BlanksApplet.class" height = 200 width = 500> <param name ="adjective1" value ="lappy"> <param name ="adjective2" value ="mouse"> <param name ="adjective3" value ="keyboard"> </applet> Some body help me........
chinmaya kumar bhatta
March 7, 2012
java

what is applet viewer ?
ANKIT
March 1, 2012
I HAVE A DOUBT

after appletviewer filename.html the applet is not running what to do now plz help
leynil pascual
March 12, 2012
compro2

hello sir/mam i want to ask can we run our applet on browser if it also contains swings companent also plz tell me????????///
naresh
March 21, 2012
applet viewer.html

when the result i see compand prompt or jcreator
John Reynolds
May 14, 2012
Cant't just view applet,html file

Click executes the file Open with TextEdit executes the file Ctrl click executes the file Open executes the file I jut wanna view/edit it but can't figure out "how". Whats the secret> Thanks John
jitesh
August 27, 2012
applets viewer are not loaded

i got the error as below C:\Program Files\Java\jdk1.7.0\bin>appletviewer be.java java.lang.NullPointerException at be.init(be.java:15) at sun.applet.AppletPanel.run(AppletPanel.java:435) at java.lang.Thread.run(Thread.java:674)
MD. Parvez Mosaraf
September 2, 2012
Rajshahi,Bangladesh.

Thank you web Developer .
mani
October 23, 2012
quest

how to run applet program using applet viewer command.....?
anil
March 8, 2013
java

what is syncronzation and explain withexample
anil
March 8, 2013
java

applet
aman
February 28, 2014
Start : applet not initialized

E:\java>appletviewer AppletParameter.html java.lang.NumberFormatException: null at java.lang.Integer.parseInt(Integer.java:454) at java.lang.Integer.parseInt(Integer.java:527) at AppletParameter.init(AppletParameter.java:17) at sun.applet.AppletPanel.run(AppletPanel.java:435) at java.lang.Thread.run(Thread.java:744)
ANJU
September 9, 2013
warning in running applet program

Warning: Can't read AppletViewer properties file: C:\Users\DALIP\.hotjava\proper ties Using defaults.
DMCA.com