Chapter 3 Introduction to Java Applets 111 3.2.2 (Web file server)
Chapter 3 Introduction to Java Applets 111 3.2.2 The DrawTest Applet The next applet we demonstrate allows you to draw lines and points in different colors. To draw, you simply drag the mouse on the applet by pressing a mouse button and holding it while you drag the mouse. For this example, change directories to directory applets, then to subdirectory DrawTest. In that directory is the example1.htmlfile that is used to execute the applet. In the command window, type the command appletviewer example1.html and press the Enter key. This executes the appletviewer. The appletviewerloads the HTML file specified as its command-line argument (example1.htmlagain), determines from the file which applet to load and begins execution of the applet. Figure 3.4 shows a screen capture of this applet after drawing some lines and points. The default shape to draw is a line and the default color is black, so you can draw black lines by dragging the mouse across the applet. To drag the mouse, press and hold the mouse button and move the mouse. Notice that the line follows the mouse pointer around the applet. The line is not permanent until you release the mouse button. You can then start a new line by repeating the process. Select a color by clicking the circle inside one of the colored rectangles at the bottom of the applet. You can select from red, green, blue, pink, orange and black. The GUI components used to present these options are commonly known as radio buttons. If you think of a car radio, only one radio station can be selected at a time. Similarly, only one drawing color can be selected at a time. Drag the mouse pointer here to draw. Select the drawing color by clicking the circle for the color you want. These GUI components are commonly known as radio buttons. Select the shape to draw by clicking the down arrow, then clicking Lines or Points. This GUI component is commonly known as a combo box, choice or drop- down list. Fig. 3.4Sample execution of applet DrawTest. Fig. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01