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. Applet viewer.
CONTENTS
The Java applet viewer (AppletViewer)is a tool used to run applets without the need for a Web browser.In this chapter, you learn how the applet viewer works, as wellas how to use it to run Java applets. You then learn how to usethe applet viewer to debug programs, along with how to use itin conjunction with the runtime interpreter to profile executingJava code in an applet. You finish up the chapter by taking alook at the documented bugs in the current release of the appletviewer.
Overview
The typical method of executing a Java applet is from within aWeb browser that has a Web page loaded containing the applet.This is the typical scenario in which most Web users come intocontact with Java applets. As a Java developer, you have anotheroption for running Java applets that doesn't involve the use ofa 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 Webbrowser to test an applet, in which case the applet viewer isan ideal alternative.
Even though the applet viewer logically takes the place of a Webbrowser, it functions very differently than a Web browser. Theapplet viewer operates on HTML documents, but all it looks foris embedded applet tags; any other HTML code in the document isignored. Each time the applet viewer encounters an applet tagin an HTML document, it launches a separate applet viewer windowcontaining the respective applet.
The only drawback to using the applet viewer is that it won'tshow you how an applet will run within the confines of a realWeb setting. Because the applet viewer ignores all HTML codesexcept applet tags, it doesn't even attempt to display any otherinformation contained in the HTML document. So, once you've testedyour applet using the applet viewer, be sure you also test itusing a Web browser, just to make sure that it works OK in thecontext of a real Web page.
Usage
The Java applet viewer is a command-line tool, meaning that itis invoked from a command prompt. The syntax for the applet viewerfollows:
appletviewer OptionsURL
The URL argument specifiesa document URL containing an HTML page with an embedded Java applet.The applet viewer launches a separate window for each applet embeddedin the HTML document. If the document doesn't contain any embeddedapplets, the applet viewer will simply exit. Figure 11.1 showsthe applet viewer in action.
Figure 11.1 shows the Animator demo applet that comes with theJava Developer's Kit running in the applet viewer. The appletwas launched in the applet viewer by changing to the directorycontaining the Animator bytecode class and embedded HTML file,and then executing the following statement at the command prompt:
appletviewer example1.html
example1.html is the HTMLfile containing the embedded Java applet. As you can see, there'snothing complicated about running Java applets using the appletviewer. The applet viewer is a useful and easy-to-use tool fortesting Java applets in a simple environment.
Options
The Options argumentto the applet viewer specifies how to run the Java applet. Thereis currently only one option supported by the applet viewer, -debug.The -debug option startsthe applet viewer in the Java debugger, which enables you to debugapplets. For more information about debugging Java programs usingthe Java debugger, refer to Chapter 15,'jdb: The Java Debugger.'
Commands
The applet viewer has a drop-down menu called Applet containinga group of commands, as shown in Figure 11.2.
The Restart command restartsthe currently loaded applet, resulting in a call to the startmethod for the applet. The Restartcommand does not reload the applet. Similar to Restart,the Reload command reloadsthe applet and then starts it. Reloadis often a better command to use to restart applets because itensures that an applet is completely reinitialized.
![Java Java](/uploads/1/2/5/1/125195800/914073809.png)
The Clone command launchesanother instance of the applet viewer executing the same applet.This command is useful when you want to run multiple copies ofan applet. For example, a multiuser network applet might supportmultiple instances that can communicate with each other. You couldload one instance of the applet and then use the Clonecommand to start other instances.
The Tag command displaysa window showing the HTML applet tag for the executing applet.The Applet HTML Tag window is shown in Figure 11.3.
The Info command displaysa window showing information about the executing applet, includinggeneral applet information and information relating to the parametersused by the applet. This information is returned by the getAppletInfoand getParameterInfo methodsof the Applet class. TheApplet Info window is shown in Figure 11.4.
The Edit command is disabledin the current release of the applet viewer. Presumably, it willbe activated in a future release of the applet viewer, in whichcase it will probably provide a way to alter the applet parametersin the HTML document containing the applet tag.
The Properties command displaysa window with access options relating to HTTP and firewall proxiesand servers, along with network and class access options. Theapplet viewer Properties window is shown in Figure 11.5.
Finally, the Close and Quitcommands perform the same function, which is shutting down theapplet viewer. It's not clear why there are two different commandsfor closing the applet viewer-it's presumably an oversight.
ProfilingJava Applets
In the previous chapter, 'java: The Java Interpreter,'the profiler built into the Java runtime interpreter was discussed.This profiler can be used to profile Java applets by running itin conjunction with the applet viewer. In this case, the appletviewer is launched from within the runtime interpreter, like this:
java -prof sun.applet.AppletViewer URL
URL specifies thename of the HTML file containing an applet tag (or tags). Noticethat the applet viewer is referenced using its fully qualifiedclass name, AppletViewer.When you finish running the applet, the interpreter writes a textfile named java.prof to thecurrent directory. This file contains profile information forthe applet you just ran. Please refer to the previous chapterfor more information regarding the meaning of the contents ofthis file.
Bugs
The latest release of the Java Developer's Kit as of this writingis 1.02, which contains some known bugs. More specifically, thefollowing Java applet viewer bugs have been documented and acknowledgedby the JavaSoft development team:
- Transparent images draw incorrectly usingATI video cards (Windows 95/NT version only).
- The Applet HTML Tag window does not displaythe HTML Applet tag width and height correctly.
- File URLs can only be debugged in localdirectories.
The first bug applies only to Windows 95/NT systems with ATI videocards. On these systems, transparent images are drawn with theircolors reversed. This problem is related to the ATI Windows videodriver, for which a fix will no doubt appear in the near future.
The second bug has to do with the applet width and height shownin the Applet HTML Tag window. Rather than displaying the appletwidth and height as specified in the HTML tag, the window displaysthe actual applet width and height, which can potentially be different.
The last bug appears when running the applet viewer in debug modeand accessing file URLs that aren't in the current working directory.The bug causes these URLs to throw exceptions when they are referenced.For now, the solution is to set the current working directoryto the directory containing the class to be debugged or to referencethe applet by an HTTP URL (rather than a file URL).
Summary
This chapter covered the Java applet viewer, which allows youto run Java applets without the help of a Web browser. You learnedhow to use the applet viewer, along with which options and commandsare available to tweak the execution of applets and obtain extrainformation. You then learned how to use the runtime interpreterprofiler in conjunction with the applet viewer to profile Javaapplets. The chapter finished up by taking a look at the bugspresent in the JDK 1.02 release of the applet viewer.
AppletViewer is a standalone command-line program from Sun to run Java applets. Appletviewer is generally used by developers for testing their applets before deploying them to a website.
As a Java developer, it is a preferred option for running Java applets that do not involve the use of a web browser. Even though the applet viewer logically takes the place of a web browser, it functions very differently from 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 will not show 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 does not even attempt to display any other information contained in the HTML document.
An Applet viewer creates an environment that mocks the look and feel of a stand-alone program with no interaction with a web browser, even though it does involve a browser to run an applet.
Appletviewer is included with Sun's JDK package, but not with Sun's JRE package. The Java development kit GCJ also has its own version of appletviewer, called 'gappletviewer'.
External links[edit]
- The Java Website
- Java SE Downloads, JDK download page
- JDK Development Tools, includes detailed documentation of appletviewer and other Java tools
Retrieved from 'https://en.wikipedia.org/w/index.php?title=AppletViewer&oldid=932450480'