How To Create Your Own AppletViewer In Java


In this article we discuss appletviewer in Java and how to create your own appletviewer.


The Java appletviewer command allows you to run applets outside or without a web browser. It is compatible with the tool supplied by Sun Microsystems, the appletviewer. Appletviewer is generally used by developers for testing their applets before deploying them to a website.

For running the appletviewer tool, we need the use of the Native Abstract Window Toolkit (NAWT). 

In Java, it is the best option for running Java applets without the use of a web browser. Appletviewer is generally used since they fill the place of web browser, it functions very differently from a web browser. It operates on HTML documents. Each time the applet viewer encounters an applet tag in an HTML document, it launches a separate applet viewer window containing the respective applet.


This figure illustrates the appletviewer in Java. In this figure an applet class containing the string "welcome-to-applet-in-java" will be shown by an appletviewer.


  1. Applet-viewer is used to burn study CDs/DVDs.
  2. Full-fledged diagnostic viewer, FDA cleared and CE certified, that may be used on computers having Java installed in it, without installing the full OnePacs study download and workstation software.

How to create your own AppletViewer

As you know, the appletviewer tool creates a frame and displays the output of the applet in the frame. You can also create your frame and display the applet output.


First we create a simple applet class, "". This class contains the "drawString" method to display the string message "welcome to".

import java.awt.Graphics;

import java.applet.Applet;

public class GraphicsEx extends Applet


public void paint(Graphics grp)


grp.drawString("welcome to", 50, 50);



Now, we write the code for the program that works like the appletviewer tool.

import java.awt.Frame;

import java.awt.Graphics;

import java.applet.Applet;

public class MyAppletViewer extends Frame


    public static void main(String[] args) throws Exception


        Class cls=Class.forName(args[0]);

        MyAppletViewer apltv=new MyAppletViewer();




        Applet aplt=(Applet)cls.newInstance();


        Graphics grp=apltv.getGraphics();






<applet code="MyAppletViewer.class" width="400" height="400">




First we compile our programs as in the following.


Now show our program that works like an appletviewer tool, in other words we have created our own appletviewer tool.