9.8 (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels
Programs often use labels when they need to display information or instructions to the user in a graphical user interface. Labels are a convenient way of identifying GUI components on the screen and keeping the user informed about the current state of the program. In Java, an object of class JLabel (from package javax.swing) can display text, an image or both. The example in Fig. 9.13 demonstrates several JLabel features, including a plain text label, an image label and a label with both text and an image.
Lines 3–6 import the classes we need to display JLabels. BorderLayout from package java.awt contains constants that specify where we can place GUI components ...
Get Java How to Program (early objects), 9/e 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.