📄 selectpanel.java
字号:
/* * SelectPanel.java * The package panels contains the different class executing the different windows of each function of the FlightSystem Reservation. */package reservation.system.panels;import reservation.system.functions.Functions;import reservation.system.Profile;import reservation.system.Flight;import reservation.system.Person;import reservation.system.Pos;import reservation.CustomDialog;import javax.swing.*;import javax.swing.border.*;import javax.swing.table.*;import java.awt.event.*;import java.util.Vector;import java.awt.Dimension;import java.util.StringTokenizer;/** * This class hold Select structure. This object allows to see the persons who have got a same bookingNumber or the persons present in a same flight. * It use a GUI that contains a form with the several field to fill. * @author Texier Mathieu and Frederic Bidon */public class SelectPanel extends Panels { /** Creates new form SelectPanel */ public SelectPanel() { flightSelect = new JComboBox(); bookingSelect = new JComboBox(); personNameInput = new JTextField(); colInput = new JTextField(); flightLabel = new JLabel(); personNameLabel = new JLabel(); bookingLabel = new JLabel(); colLabel = new JLabel(); rowLabel = new JLabel(); rowInput = new JTextField(); searchButton = new JButton(); jScrollPane = new JScrollPane(); bookingTable = new JTable(); add(flightSelect); add(bookingSelect); add(personNameInput); add(colInput); flightLabel.setText("Flight"); add(flightLabel); personNameLabel.setText("Person"); add(personNameLabel); bookingLabel.setText("Booking"); add(bookingLabel); colLabel.setText("Seat col"); add(colLabel); rowLabel.setText("row"); add(rowLabel); add(rowInput); searchButton.setText("Search"); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { searchAction(evt); } }); add(searchButton); jScrollPane.setBorder(new SoftBevelBorder(BevelBorder.RAISED)); bookingTable.setRowSelectionAllowed(false); jScrollPane.setViewportView(bookingTable); add(jScrollPane); } /** * Create the button of validation to search in the database the persons who have the same bookingNumber or who are registered in the same flight. */ private void searchAction(ActionEvent evt) { Vector groupePersonVector = null; try { Profile profile = new Profile(); String personName = (String) personNameInput.getText(); if (personName != null) if (!personName.equals("")) profile.setPersonName(personName); String flightName = (String) flightSelect.getSelectedItem(); if (flightName != null) if (!flightName.equals("")) profile.setFlight(fs.selectFlight(flightName)); Integer bookingNumber = (Integer) bookingSelect.getSelectedItem(); if (bookingNumber != null) { profile.setBookingNumber(bookingNumber.intValue()); } String colString = colInput.getText(); String rowString = rowInput.getText(); if ((colString != null) && (rowString != null)) { if (colString.equals("") ^ rowString.equals("")) { throw new Exception("Both col and row have to be either null or non null"); } if (!colString.equals("") && !rowString.equals("")) if (Functions.checkInteger(colString, 1, Flight.ROWS_MAX) && Functions.checkInteger(rowString, 1, Flight.ROW_LENGTH_MAX)) { short col = (short) Integer.parseInt(colString); short row = (short) Integer.parseInt(rowString); Pos pos = new Pos(row,col); profile.setPos(pos); } else { colInput.setText(""); rowInput.setText(""); throw new Exception("Col or Row have incorect value"); } } groupePersonVector = fs.search(profile); } catch (Exception e) { CustomDialog.alert(e); } if (groupePersonVector != null) { int groupePersonSize = groupePersonVector.size(); String listData[][] = new String[groupePersonSize][4]; String title[] = {"Name", "Booking number", "flight name", "seat"}; for (int i=0; i< groupePersonSize; i++) { try { Person person = (Person) groupePersonVector.get(i); listData[i][0] = person.getPersonName(); listData[i][1] = new Integer(person.getBookingNumber()).toString(); listData[i][2] = person.getFlight().getFlightName(); listData[i][3] = person.getPos().toString(); } catch (Exception e) {CustomDialog.alert(e);} } bookingTable.setModel(new DefaultTableModel(listData,title)); } } /** * Causes this container to lay out its components. */ public void doLayout() { flightSelect.setBounds(20, 40, 90, 20); bookingSelect.setBounds(210, 40, 80, 20); personNameInput.setBounds(130, 40, 60, 20); colInput.setBounds(310, 40, 40, 20); flightLabel.setBounds(20, 10, 40, 20); personNameLabel.setBounds(130, 10, 40, 20); bookingLabel.setBounds(210, 10, 40, 20); colLabel.setBounds(310, 10, 40, 20); rowLabel.setBounds(360, 10, 40, 20); rowInput.setBounds(360, 40, 40, 20); searchButton.setBounds(420, 40, 70, 20); jScrollPane.setBounds(20, 90, 500, 120); bookingTable.setBounds(20, 90, 500, 120); } /** * Set the size of the panel * @return an instance of Dimension that represents the minimum size of this container. */ public Dimension getMinimumSize() { return new Dimension(550,220); } /** * Set the size of the panel * @return an instance of Dimension that represents the preferred size of this container. */ public Dimension getPreferredSize() { return new Dimension(550,220); } /** * Initialize the number of the field and fill them with default values. * Dispaly the label of the Window. */ public void init() { bookingSelect.addItem(null); flightSelect.addItem(null); try { String [] flightList = fs.getFlightList(); if (flightList != null) { for (int i=0;i< flightList.length;i++) { flightSelect.addItem(flightList[i]); } } Integer [] bookingtList = fs.getBookingList(); if (bookingtList != null) { for (int i=0;i< bookingtList.length;i++) { bookingSelect.addItem(bookingtList[i]); } } } catch (Exception e) { CustomDialog.alert(e); } searchAction(null); } /** * Proceed the execution of the action * @return the result of the request. * @param unUsed not used * @throws Exception if the command is not executed. */ public String execute(String[] unUsed) throws Exception { return ""; } private JLabel bookingLabel; private JComboBox bookingSelect; private JTable bookingTable; private JTextField colInput; private JLabel colLabel; private JLabel flightLabel; private JComboBox flightSelect; private JScrollPane jScrollPane; private JTextField personNameInput; private JLabel personNameLabel; private JTextField rowInput; private JLabel rowLabel; private JButton searchButton; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -