Java Reference
In-Depth Information
16
//construct components
17
JLabel sortPrompt = new JLabel ( "Sort by:" ) ;
18
JComboBox fieldCombo = new JComboBox () ;
19
JTextPane textPane = new JTextPane () ;
20
FIGURE 7-10
The following step enters the code to construct the Swing components.
To Construct the Swing Components
1. Enter the code as shown in Figure 7-10.
TextPad displays the declaration and construction code of the Swing
components (Figure 7-11).
Swing components
constructed
FIGURE 7-11
As class-level components, the JLabel, JComboBox, and JTextPane
components all will be visible to other methods in the DVD class.
Populating a JComboBox
The ability to declare, construct, and populate a JComboBox in a
single line of code makes it easier to create long lists of options
from which users may choose. For shorter lists, populate a
JComboBox using the addItem() method.
Constructing Parallel Arrays
Part of the logic necessary for the Classics on DVD prototype program
requires that the data can be searched and sorted. Without permanent storage of
the data, the most efficient way to manipulate data is in arrays. The Classics on
DVD program will use three arrays, one for each of the fields of information:
title, studio, and year.
Search WWH ::




Custom Search