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?
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:
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:
Here is the HTML File:
After building the program, run the applet and the applet viewer as shown below.
When we run the applet viewer it will display the window as shown below.