📄 cancelpanel.java
字号:
/* * CancelPanel.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.FlightSystem;import reservation.system.Person;import reservation.system.functions.Functions;import reservation.system.functions.Cancel;import reservation.CustomDialog;import javax.swing.*;import java.awt.event.*;import java.awt.Dimension;import java.util.StringTokenizer;import java.util.Vector;/** * This class hold Cancel structure. This object allows to cancel a reservation for different person or for a whole of person by calling the methods <CODE>cancel</CODE> in {@link reservation.system.FlightSystem}. * @author Texier Mathieu and Frederic Bidon * It use a GUI that contains a form with the several field to fill. */public class CancelPanel extends Panels { /** Creates new form CancelPanel */ public CancelPanel () { action = new Cancel (); bookingLabel = new JLabel (); bookingInput = new JTextField (); identifyButton = new JButton (); passengerLabel = new JLabel (); passengerList = new JList (); passengerListScroll = new JScrollPane (); bookingLabel.setText ("Enter"); add (bookingLabel); bookingInput.setText ("booking number"); bookingInput.addMouseListener (new MouseAdapter () { public void mouseEntered (MouseEvent evt) { bookingInput.setText (""); } }); add (bookingInput); identifyButton.setText ("Identify"); identifyButton.addActionListener (new ActionListener () { public void actionPerformed (ActionEvent evt) { identifyAction (evt); } }); add (identifyButton); passengerLabel.setText ("Passenger"); add (passengerLabel); passengerListScroll.setViewportView (passengerList); add (passengerListScroll); } /** * Create the button of validation to search the bookingNumber given by the user in the database. * @throws Exception if the command is not executed. */ private void identifyAction(ActionEvent evt) { try { String bookingString = bookingInput.getText (); if (!bookingString.equals ("")) if (Functions.checkInteger (bookingString,1,fs.getBookingNumberMax ())) { int bookingNumber = Integer.parseInt (bookingString); Vector groupePersonVector = fs.identify (bookingNumber); int groupePersonSize = groupePersonVector.size (); String listData[] = new String[groupePersonSize]; for (int i=0; i< groupePersonSize; i++) { listData[i] = ((Person) groupePersonVector.get (i)).getPersonName (); } passengerList.setListData (listData); } } catch (Exception e) { CustomDialog.alert (e); } } /** * Causes this container to lay out its components. */ public void doLayout () { bookingLabel.setBounds (20, 20, 40, 20); bookingInput.setBounds (110, 20, 90, 20); identifyButton.setBounds (210, 20, 70, 20); passengerLabel.setBounds (20, 60, 80, 20); passengerList.setBounds (110, 60, 170, 60); passengerListScroll.setBounds (110, 60, 170, 60); } /** * 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 (320,140); } /** * 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 (320,140); } /** * Initialize the number of the field and fill them with default values. * Dispaly the label of the Window. */ public void init () { } /** * 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 { Object selectedPassenger[] = passengerList.getSelectedValues (); String argv[] = new String[selectedPassenger.length + 1]; argv[0] = bookingInput.getText (); System.arraycopy ( selectedPassenger, 0, argv, 1, selectedPassenger.length ); return action.execute ( argv ); } private JTextField bookingInput; private JLabel bookingLabel; private JButton identifyButton; private JLabel passengerLabel; private JList passengerList; private JScrollPane passengerListScroll;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -