Java Reference
In-Depth Information
// Setup rent and return buttons
JButton rentButton = new JButton ("Rent DVD");
JButton returnButton = new JButton ("Return DVD");
// Add the action listenters to rent and return buttons
rentButton.addActionListener(new RentDVD ());
returnButton.addActionListener(new ReturnDVD ());
// Set the rent and return buttons to refuse focus
rentButton.setRequestFocusEnabled(false);
returnButton.setRequestFocusEnabled(false);
// Add the keystroke mnemonics
rentButton.setMnemonic(KeyEvent.VK_R);
returnButton.setMnemonic(KeyEvent.VK_U);
// Create a panel to add the rental a remove buttons
JPanel hiringPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
hiringPanel.add(rentButton);
hiringPanel.add(returnButton);
// bottom panel
JPanel bottomPanel = new JPanel (new BorderLayout ());
bottomPanel.add(searchPanel, BorderLayout.NORTH);
bottomPanel.add(hiringPanel, BorderLayout.SOUTH);
// Add the bottom panel to the main window
this.add(bottomPanel, BorderLayout.SOUTH);
// Set table properties
mainTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mainTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
mainTable.setToolTipText("Select a DVD record to rent or return.");
// Add Tool Tips
returnButton.setToolTipText(
"Return the DVD item selected in the above table.");
rentButton.setToolTipText(
"Rent the DVD item selected in the above table.");
searchField.setToolTipText(
"Enter infromation about a DVD you want to locate.");
searchButton.setToolTipText("Submit the DVD search.");
}
}
The GUI created by the MainWindow class and the DVDScreen class can be seen in
Figure 8-28.
Search WWH ::




Custom Search