Page 216 - Introduction to Programming with Java: A Problem Solving Approach
P. 216

                182 Chapter 5 Using Pre-Built Methods
5.9 GUI Track: Drawing Images, Lines, Rectangles,
and Ovals in Java Applets (Optional)
This section shows you how to display images, lines, rectangles, and ovals in a GUI window. The simplest way to do this is to call methods in Java’s Graphics class from within a Java applet. As you might recall from Chapter 1, an applet is a Java program that’s embedded in a Web page. You execute a Java applet by calling it from the Web page’s HTML code (HTML is the base language for most Web pages). You can run the Web page by loading it within an Internet browser.
Image Files
Java can handle many kinds of images. Some images are stylized icons. Others are digitized photographs. For example, suppose you have a digitized photograph of a family member, like author John’s nephew, Max, shown in Figure 5.13.
            Apago PDF Enhancer
Figure 5.13 A typical image stored in a .jpg file
Suppose this photo is stored in a file named hurricanes.jpg. “Hurricanes” is the name of Max’s soccer team. The extension, “.jpg,” is short for JPEG, which stands for Joint Photographic Experts Group. Files with this extension should conform to JPEG standards for digital compression of photographic images. Exact representations of simple drawn images are usually stored in files with a “.gif” extension. GIF stands for Graphics Interchange Format. For simplicity we’ll assume that the image file is in the current direc- tory—the same directory that holds the Java program that will display it.
  

























































































   214   215   216   217   218