The Icon Interface and Class ImageIcon

Icons are a popular way to enhance the look-and-feel of an application and are also commonly used to indicate functionality. For example, the same icon is used to play most of today’s media on devices like DVD players and MP3 players. Several Swing components can display images. An icon is normally specified with an Icon (package javax.swing) argument to a constructor or to the component’s setIcon method. Class ImageIcon supports several image formats, including Graphics Interchange Format (GIF), Portable Network Graphics (PNG) and Joint Photographic Experts Group (JPEG).

Line 28 declares an ImageIcon. The file bug1.png contains the image to load and store in the ImageIcon object. This image is included ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.