I think you get the key to this question now!
1. Use JOptionPane.showConfirmDialog to ask whether the user really want to book
2. if yes,
2.1 lock,modify,unlock
2.2 reset TableModel of JTable. Code is listed below:
//refresh data in flight table
int selected = flightTable.getSelectedRow();
String origin = (String)originCmBox.getSelectedItem();
String dest = (String)destCmBox.getSelectedItem();
try {
DataInfo[] records = flight.searchFlight(ORIGIN_AIRPORT_FIELD_NAME + "='" + origin + "'," +
DEST_AIRPORT_FIELD_NAME + "='" + dest + "'");
flightTable.setModel(new FlightTableModel(records, flight.GetFlightDescription()));
} catch (Exception ex) {
}
flightTable.setRowSelectionInterval(selected, selected);
private class FlightSelectListener implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
//Ignore extra messages.
if (e.getValueIsAdjusting()) {
return;
}
ListSelectionModel lsm = (ListSelectionModel)e.getSource();
if (lsm.isSelectionEmpty()) {
......
} else {
int selectedRow = lsm.getMinSelectionIndex();
//show information of this flight in JTextFields
for (int i = 0; i < flightTable.getColumnCount(); i++) {
String columnName = flightTable.getColumnName(i);
String value = flightTable.getValueAt(selectedRow, i).toString();
//those are fields to display a flight info
((JTextField)fieldNameToTextField.get(columnName)).setText(value);
}
bookButton.setEnabled(true);
}
}
}