
12.3 A Simple Component:JLabel 829
12.3 A Simple Component: JLabel
Now it’s time to place a component into the window. We will start with a
simple component, a label, encapsulated by the JLabel class. A user does not
interact with a label; the label just displays some information, such as a
title, an identifier for another component, or an image.
Example 12.2 creates a window containing two labels, one that displays text
and one that displays an image. Figure 12.4 shows the window when the
application is run.
1 /* Using JLabels to display text and images
2 Anderson, Franceschi
3 */
4
5 import java.awt.Container;
6 import javax.swing.JFrame;
7 import javax.swing. ...