TAILIEUCHUNG - Java™ How to Program ( Deitel - Deitel) - Phần 19

Tham khảo sách 'java™ how to program ( deitel - deitel) - phần 19', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Look-and-Feel Observation Use tool tips to add descriptive text to your GUI components. This text helps the user determine the GUI component s purpose in the user interface. Creating and Attaching label2 Icons are a popular way to enhance the look-and-feel of an application and are also commonly used to indicate functionality. For examples most of today s VCRs and DVD players use the same icon to play a tape or DVD. Several Swing components can display images. An icon is normally specified with an Icon argument to a constructor or to the component s setIcon method. An Icon is an object of any class that implements interface Icon package . One such class is ImageIcon package which supports several image formats including Graphics Interchange Format GIF Portable Network Graphics PNG and Joint Photographic Experts Group JPEG . File names for each of these types end with .gif .png or .jpg or .jpeg respectively. We discuss images in more detail in Chapter 21 Multimedia Applets and Applications. Line 28 declares an ImageIcon object. The file contains the image to load and store in the ImageIcon object. This image is included in the directory for this example on the CD that accompanies this book The ImageIcon object is assigned to Icon reference bug. Remember class ImageIcon implements interface Icon an ImageIcon is an Icon. In line 28 the expression getClass .getResource invokes method getClass inherited from class Object to retrieve a reference to the Class object that represents the LabelFrame class declaration. That reference is then used to invoke Class method getResource which returns the location of the image as a URL. The ImageIcon constructor uses the URL to locate the image then loads it into memory. As we discussed in Chapter 1 the JVM loads class declarations into memory using a class loader. The class loader knows where each class it loads is located on disk. Method geTResource uses the Class object s class .

TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.