Java Reference
In-Depth Information
If the user chooses to quit the application using the Quit menu item, the event handler
will call the QuitApplication class. This is one of the simplest event handlers we could write—
all it does is call System.exit(0) . It is shown in Listing 8-22.
Listing 8-22. The QuitApplication ActionListener
private class QuitApplication implements ActionListener {
public void actionPerformed (ActionEvent ae) {
System.exit(0);
}
}
Listing 8-23 contains the DVDScreen constructor. The major components of this have all
been introduced in the earlier sections.
DVDScreen starts by adding a scroll pane for the table holding the DVDs—this is added to
the center of the JPanel .
Following this, the panel for the search options is created, along the way creating the text
field for entering the search parameters, and the button to begin a search. An action listener
is added to the search button, and will be described after Listing 8-23 since it is a little more
involved than our application listener for the Quit menu item.
Then the buttons and panel for the Rent and Return options are created, along with their
action listeners.
A bottom panel is created to hold both the search options and the hiring options, with the
search options panel added to the north, and the hiring options panel added to the south. The
bottom panel is then added to the south of the master JPanel .
Finally the table is configured and some tooltips are added.
Listing 8-23. The DVDScreen
public DvdScreen() {
this.setLayout(new BorderLayout());
JScrollPane tableScroll = new JScrollPane (mainTable);
tableScroll.setSize(500, 250);
this.add(tableScroll, BorderLayout.CENTER);
// Set up the search pane
JButton searchButton = new JButton ("Search");
searchButton.addActionListener(new SearchDVD ());
searchButton.setMnemonic(KeyEvent.VK_S);
// Search panel
JPanel searchPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
searchPanel.add(searchField);
searchPanel.add(searchButton);
Search WWH ::




Custom Search