< Day Day Up > |
Sending Parameters to the AppletBecause the Animate applet relies on parameters to specify the image files it should display, you need to create a web page containing these filenames before you can test the program. After saving and compiling the Animate.java file, open up a new file in your word processor and call it Animate.html. Enter Listing 24.2 into that file and save it when you're done. Listing 24.2. The Full Text of Animate.html1: <applet code="Animate.class" width="215" height="298"> 2: <param name="image0" value="lh0.gif"> 3: <param name="image1" value="lh1.gif"> 4: <param name="image2" value="lh2.gif"> 5: <param name="image3" value="lh3.gif"> 6: <param name="pause" value="800"> 7: </applet> This file specifies four image files: lh0.gif, lh1.gif, lh2.gif, and lh3.gif. These files are listed as the values for the parameters image0 through image3. You can find the files used in this example on the Hour 24 page of the book's website at http://www.java24hours.com. You also can specify any of your own GIF or JPEG files, if desired. Whichever files you choose should be placed in the same folder as the Animate.class and Animate.html files. With the pause parameter, you can specify how long the program should pause after each image is displayed. Once the files have been put in the right place, you're ready to try out the Animate applet. Type the following command to open the page in your web browser and view the applet: Animate.html Figure 24.1 shows one of the four images being displayed as the applet runs. Figure 24.1. Animating GIF files in an applet.Although this is a simple animation program, hundreds of applets on the web use similar functionality to present a series of image files as an animation. Presenting a sequence of image files through Java is similar to the animated GIF files that are becoming more commonplace on web pages. Although Java applets are often slower to load than these GIF files, they can provide more control of the animation and allow for more complicated effects. |
< Day Day Up > |