One of the easiest ways to improve the visual appeal of a GUI is to use icons, small images used to identify buttons and other parts of an interface.
With many of the components in the Swing class library, you can label a component with an image instead of text by using the
ImageIcon class in the
Although some operating systems use the
\ character to separate folders and filenames, the
ImageIcon constructor requires the
/ character as a separator.
You can create an
ImageIcon from a file on your computer by calling the
) constructor method. The argument to the method is either the name of the file or its location and name, as in these examples:
ImageIcon stopSign = ...