1、1 外文原文 More Animation Images and Sound Animations are fun and easy to do in Java, but theres only so much you can do with the builtin,Java methods for lines and fonts and colors. For really interestinganimations, you have toprovide your own images for each frame of the animationand having sounds is
2、nice, as well.Today, youll do more with animations, incorporating images and sounds into Java applets.Specifically, youll explore the following topics: 1. Using imagesgetting them from the server, loading them into Java, and displaying them in your applet 2. Creating animations by using images, incl
3、uding an extensive example 3. Using soundsgetting them and playing them at the appropriate times 4. Suns Animator appletan easy way to organize animations and sounds in Java 5. Double-bufferinghardcore flicker avoidance Retrieving and Using Images Basic image handling in Java is easy. The Image clas
4、s in java.awt provides abstract methods to represent common image behavior, and special methods defined in Applet and Graphics give you everything you need to load and display images in your applet as easily as drawing a rectangle. In this section, youll learn about how to get and draw images in you
5、r Java applets. Getting Images To display an image in your applet, you first must load that image over the net into your Java program. Images are stored as separate files from your Java class files, so you have to tell Java where to find them. The Applet class provides a method called getImage, whic
6、h loads an image and automatically creates an instance of the Image class for you. To use it, all you have to do is import the java.awt.Image class, and then give getImage the URL of the image you want to load. There are two ways of doing the latter step: 1. The getImage method with a single argument (an object of type URL) retrieves the image at that URL. The getImage method with two arguments: the base URL (also a URL object) and a string representing the path or filename of the actu