16 - Labels

16 - Labels - CSc 2700: Lecture # 16 Labels October 23,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CSc 2700: Lecture # 16 Labels October 23, 2008 1 Introduction A label is an area that can be used to display text or images. A label is not the source of events. Here are the basics: Class: JLabel Constructors: JLabel() instantiates a JLabel object that displays neither text nor an image. JLabel (String text) instantiates a JLabel object with text, text JLabel(Icon icon) e.g. JLabel label = new JLabel( new ImageIcon(”pic.jpg”)) instantiates a JLabel object that displays icon. JLabel(String text, int horizontalAlignment) instantiates a JLabel object that displays, text. Alignment is deter- mined by one of the SwingConstants: LEFT , RIGHT, CENTER JLabel( Icon icon, int horizontalAlignment) instantiates a JLabel object that displays icon. Alignment is deter- mined by one of the SwingConstants: LEFT , RIGHT, CENTER JLabel(String text, Icon icon, int horizontalAlignment) instantiates a JLabel that displays text and icon. Alignment is deter- mined by one of the SwingConstants: LEFT , RIGHT, CENTER 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
setText(String text) and setAlignment(int alignment). The following example uses buttons and labels to create an electronic photo album. The buttons are the source of all events in this class. The labels are used for display. 2 A Photo Album Using JLabels This is an application that displays nine thumbnail pictures in a single frame. When you clicks on any thumbnail, a full size version shows in another frame. The lower panel of the thumbnail frame contains two buttons, a Next button and an Exit button. When the Next button is clicked, the next batch of nine thumbnail pictures comes into view. After the last (270th) thumbnail is shown, the display cycles around and the Frst thumbnail is once again displayed. The Exit button terminates the application. ±igure 1 shows the Frst ”tray” of thumbnails. The following program consists of three interacting ±igure 1: Nine Thumbnail Pictures Displayed in a ±rame classes: 1. PhotoAlbum PhotoAlbum class maintains two ArrayList¡ImageIcon¿ objects: one list holds full size photos, the other thumbnails. PhotoAlbum provides methods that return the number of photos, the ith photo, or the ith thumbnail as well as a method that adds a new thumbnail/photo pair to the lists. 2
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

16 - Labels - CSc 2700: Lecture # 16 Labels October 23,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online