Java Reference
In-Depth Information
//call sort method
232
sort ( title ) ;
233
fieldCombo.setSelectedIndex ( 0 ) ;
234
}
235
236
237
//user clicks Title on the Search submenu
if ( arg == "title" )
238
search ( arg, title ) ;
239
240
241
//user clicks Studio on the Search submenu
if ( arg == "studio" )
242
search ( arg, studio ) ;
243
244
245
//user clicks Year on the Search submenu
if ( arg == "year" )
246
search ( arg, year ) ;
247
}
248
249
FIGURE 7-26 (continued)
In line 191, the Action Event is returned to a String variable named arg,
as in previous chapters. The variable, arg, then can reference any of the menu
commands.
In line 194, the source of the click first is compared with the JComboBox
named fieldCombo. If fieldCombo is the object that the user clicked, the index
number of the clicked item in the list becomes the integer for the switch state-
ment. If the index is 0, the user clicked Title. If it is 1, the user clicked Studio,
and so on. With each click in the JComboBox, a sort() method is called, which
will be coded later in the chapter.
Then, one at a time, the actionPerformed() method evaluates each of the
menu options for possible clicks. For example, if the user clicks the Exit
command, then the program exits in line 212. If the user clicks Insert, the
JOptionPane dialog boxes are displayed to collect the new information in lines
218, 219, and 220.
Arrays are not dynamically enlarged in Java; therefore, an enlargeArray()
method will be coded later in the chapter to accept the old data and create a new
array with additional elements. The new array is rewritten over the top of the old
array in lines 223, 224, and 225. Next, the new data is added to each array (lines
228, 229, and 230); the new array is sent to the sort() method in line 233, and
the JComboBox is reset in line 234.
If the user clicks any of the three commands on the Search submenu, the
field name and array are sent to a method called search(), coded later in the
chapter (lines 238 through 247).
The following step enters code for the actionPerformed() method.
Search WWH ::




Custom Search