Introduction+to+Programming+Using+Java+09 - Chapter 12...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Chapter 12 Advanced GUI Programming I t’s possible to program a wide variety of GUI applications using only the techniques cov- ered in Chapter 6. In many cases, the basic events, components, layouts, and graphics routines covered in that chapter suffice. But the Swing graphical user interface library is far richer than what we have seen so far, and it can be used to build highly sophisticated applications. This chapter is a further introduction to Swing and other aspects of GUI programming. Although the title of the chapter is “Advanced GUI Programming,” it is still just an introduction. Full coverage of this topic would require at least another complete book. 12.1 Images and Resources W e have seen how to use the Graphics class to draw on a GUI component that is visible on the computer’s screen. Often, however, it is useful to be able to create a drawing off-screen , in the computer’s memory. It is also important to be able to work with images that are stored in files. To a computer, an image is just a set of numbers. The numbers specify the color of each pixel in the image. The numbers that represent the image on the computer’s screen are stored in a part of memory called a frame buffer . Many times each second, the computer’s video card reads the data in the frame buffer and colors each pixel on the screen according to that data. Whenever the computer needs to make some change to the screen, it writes some new numbers to the frame buffer, and the change appears on the screen a fraction of a second later, the next time the screen is redrawn by the video card. Since it’s just a set of numbers, the data for an image doesn’t have to be stored in a frame buffer. It can be stored elsewhere in the computer’s memory. It can be stored in a file on the computer’s hard disk. Just like any other data file, an image file can be downloaded over the Internet. Java includes standard classes and subroutines that can be used to copy image data from one part of memory to another and to get data from an image file and use it to display the image on the screen. 12.1.1 Images and BufferedImages The class java.awt.Image represents an image stored in the computer’s memory. There are two fundamentally different types of Image . One kind represents an image read from a source outside the program, such as from a file on the computer’s hard disk or over a network connection. The second type is an image created by the program. I refer to this second type as an off-screen canvas . An off-screen canvas is a region of the computer’s memory that can be used as a 611 612 CHAPTER 12. ADVANCED GUI PROGRAMMING drawing surface. It is possible to draw to an offscreen image using the same Graphics class that is used for drawing on the screen....
View Full Document

This document was uploaded on 08/10/2011.

Page1 / 73

Introduction+to+Programming+Using+Java+09 - Chapter 12...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online