Chapter 3 Introduction to Java Applets 119 1 (Web file server)
Chapter 3 Introduction to Java Applets 119 1 2 4 Fig. 3.7 WelcomeApplet.htmlloads class WelcomeAppletof Fig. 3.6 into the appletviewer. Good Programming Practice 3.2 Always test a Java applet in the appletviewer and ensure that it is executing correctly before loading the applet into a World Wide Web browser. Browsers often save a copy of an applet in memory until the current browsing session terminates (i.e., all browser windows are closed). Thus, if you change an applet, recompile the applet, then reload the applet in the browser, you may not see the changes because the browser may still be executing the original version of the applet. Close all your browser windows to remove the old version of the applet from memory. Open a new browser window and load the applet to see your changes. Software Engineering Observation 3.1 If your World Wide Web browser does not support Java 2, most of the applets in this book will not execute in your browser. This is because most of the applets in this book use features that are specific to Java 2 or are not provided by browsers that support Java 1.1. Section 3.6.2 discusses how to use the Java Plug-in to view applets in Web browsers that do not support Java 2. Many HTML codes (or tags) come in pairs. For example, lines 1 and 4 of Fig. 3.7 indicate the beginning and the end, respectively, of the HTML tags in the file. All HTML tags begin with a left angle bracket, <, and end with a right angle bracket, >. Lines 2 and 3 are special HTML tags for Java applets. They tell the applet container to load a specific applet and define the size of the applet s display area (its width and height in pixels) in the appletviewer(or browser). Normally, the applet and its corresponding HTML file are stored in the same directory on disk. Typically, a browser loads an HTML file from a computer (other than your own) connected to the Internet. However, HTML files also can reside on your computer (as we demonstrated in Section 3.2). When an applet container encounters an HTML file that specifies an applet to execute, the applet container automatically loads the applet s .classfile (or files) from the same directory on the computer in which the HTML file resides. The