120 Introduction to Java Applets Chapter 3 Software (Msn web hosting)

120 Introduction to Java Applets Chapter 3 Software Engineering Observation 3.2 Generally, each applet should be less than 800 pixels wide and 600 pixels tall (most computer screens support these dimensions as the minimum width and height). Common Programming Error 3.3 Placing additional characters such as commas (,) between the attributes in the tag may cause the appletviewer or browser to produce an error message indicating a MissingResourceException when loading the applet. Common Programming Error 3.4 Forgetting the ending tag prevents the applet from loading into the applet- viewer or browser properly. Testing and Debugging Tip 3.5 If you receive a MissingResourceException error message when loading an applet into the appletviewer or a browser, check the tag in the HTML file carefully for syntax errors. Compare your HTML file to the file in Fig. 3.7 to confirm proper syntax. The appletviewer understands only the and HTML tags, so it is sometimes referred to as the minimal browser (it ignores all other HTML tags). The appletviewer is an ideal place to test an applet and ensure that it executes properly. Once the applet s execution is verified, you can add the applet s HTML tags to an HTML file that will be viewed by people browsing the Internet. To execute the WelcomeApplet in the appletviewer open a command window, change to the directory containing your applet and HTML file and type the command appletviewer WelcomeApplet.html Note that the appletviewerrequires an HTML file to load an applet. This is different from the java interpreter for applications which requires only the class name of the application class. Also, the preceding command must be issued from the directory in which the HTML file and the applet s .class file are located. Common Programming Error 3.5 Running the appletviewer with a file name that does not end with .html or .htm is an error that prevents the appletviewer from loading your applet for execution. Portability Tip 3.2 Test your applets in every browser used by people who view your applet. This will help ensure that people who view your applet experience the functionality you expect. [Note: A goal of the Java Plug-In (discussed later in the book) is to provide consistent applet execution across many different browsers.] 3.4 Two More Simple Applets: Drawing Strings and Lines Let us consider another applet. An applet can draw WelcometoJavaProgramming! several ways. For example, an applet can use two drawString statements in method paint to print multiple lines of text as in Fig. 3.8. The HTML file to load the applet into an applet container is shown in Fig. 3.9. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01

Leave a Reply