Monday 11 May 2015

Using the Applet Viewer in Java

Overview

The typical method of executing a Java applet is from within a Web browser that has a Web page loaded containing the applet. This is the typical scenario in which most Web users come into contact with Java applets. As a Java developer, you have another option for running Java applets that doesn't involve the use of a Web browser. This option involves using the Java applet viewer, which is a tool that serves as a minimal test bed for Java applets. At times, you may not want to hassle with using a full-blown Web browser to test an applet, in which case the applet viewer is an ideal alternative.

Even though the applet viewer logically takes the place of a Web browser, it functions very differently than a Web browser. The applet viewer operates on HTML documents, but all it looks for is embedded applet tags; any other HTML code in the document is ignored. Each time the applet viewer encounters an applet tag in an HTML document, it launches a separate applet viewer window containing the respective applet.

The only drawback to using the applet viewer is that it won't show you how an applet will run within the confines of a real Web setting. Because the applet viewer ignores all HTML codes except applet tags, it doesn't even attempt to display any other information contained in the HTML document. So, once you've tested your applet using the applet viewer, be sure you also test it using a Web browser, just to make sure that it works OK in the context of a real Web page.

Usage

The Java applet viewer is a command-line tool, meaning that it is invoked from a command prompt. The syntax for the applet viewer follows:
appletviewer Options URL

The URL argument specifies a document URL containing an HTML page with an embedded Java applet. The applet viewer launches a separate window for each applet embedded in the HTML document. If the document doesn't contain any embedded applets, the applet viewer will simply exit.

No comments:

Post a Comment