booking system

  1. /*
  2.  * CancelPanel.java
  3.  * The package panels contains the different class executing the different windows of each function of the FlightSystem Reservation.
  4.  */
  5. package reservation.system.panels;
  6.  
  7. import reservation.system.FlightSystem;
  8. import reservation.system.Person;
  9. import reservation.system.functions.Functions;
  10. import reservation.system.functions.Cancel;
  11. import reservation.CustomDialog;
  12.  
  13. import javax.swing.*;
  14. import java.awt.event.*;
  15. import java.awt.Dimension;
  16. import java.util.StringTokenizer;
  17. import java.util.Vector;
  18.  
  19. /**
  20.  * 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}.
  21.  * @author Texier Mathieu and Frederic Bidon
  22.  * It use a GUI that contains a form with the several field to fill.
  23.  */
  24. public class CancelPanel extends Panels {
  25.    
  26.     /** Creates new form CancelPanel */
  27.     public CancelPanel () {
  28.         action = new Cancel ();
  29.        
  30.         bookingLabel = new JLabel ();
  31.         bookingInput = new JTextField ();
  32.         identifyButton = new JButton ();
  33.         passengerLabel = new JLabel ();
  34.         passengerList = new JList ();
  35.         passengerListScroll = new JScrollPane ();
  36.        
  37.         bookingLabel.setText ("Enter");
  38.         add (bookingLabel);
  39.        
  40.         bookingInput.setText ("booking number");
  41.         bookingInput.addMouseListener (new MouseAdapter () {
  42.             public void mouseEntered (MouseEvent evt) {
  43.                 bookingInput.setText ("");
  44.             }
  45.         });
  46.         add (bookingInput);
  47.        
  48.         identifyButton.setText ("Identify");
  49.         identifyButton.addActionListener (new ActionListener () {
  50.             public void actionPerformed (ActionEvent evt) {
  51.                 identifyAction (evt);
  52.             }
  53.         });
  54.         add (identifyButton);
  55.        
  56.         passengerLabel.setText ("Passenger");
  57.         add (passengerLabel);
  58.        
  59.         passengerListScroll.setViewportView (passengerList);
  60.         add (passengerListScroll);
  61.     }
  62.    
  63.    /**
  64.     * Create the button of validation to search the bookingNumber given by the user in the database.
  65.     * @throws Exception if the command is not executed.
  66.     */    
  67.     private void identifyAction(ActionEvent evt) {
  68.         try {
  69.             String bookingString = bookingInput.getText ();
  70.             if (!bookingString.equals (""))
  71.                 if (Functions.checkInteger (bookingString,1,fs.getBookingNumberMax ())) {
  72.                     int bookingNumber = Integer.parseInt (bookingString);
  73.                     Vector groupePersonVector = fs.identify (bookingNumber);
  74.                     int groupePersonSize = groupePersonVector.size ();
  75.                     String listData[] = new String[groupePersonSize];
  76.                     for (int i=0; i< groupePersonSize; i++) {
  77.                         listData[i] = ((Person) groupePersonVector.get (i)).getPersonName ();
  78.                     }
  79.                     passengerList.setListData (listData);
  80.                 }
  81.         } catch (Exception e) {
  82.             CustomDialog.alert (e);
  83.         }
  84.     }
  85.  
  86.   /**
  87.    * Causes this container to lay out its components.
  88.    */
  89.     public void doLayout () {
  90.         bookingLabel.setBounds (20, 20, 40, 20);
  91.         bookingInput.setBounds (110, 20, 90, 20);
  92.         identifyButton.setBounds (210, 20, 70, 20);
  93.         passengerLabel.setBounds (20, 60, 80, 20);
  94.         passengerList.setBounds (110, 60, 170, 60);
  95.         passengerListScroll.setBounds (110, 60, 170, 60);
  96.     }
  97.  
  98.     /**
  99.      * Set the size of the panel
  100.      * @return an instance of Dimension that represents the minimum size of this container.
  101.      */
  102.     public Dimension getMinimumSize () {
  103.         return new Dimension (320,140);
  104.     }
  105.  
  106.     /**
  107.      * Set the size of the panel
  108.      * @return an instance of Dimension that represents the preferred size of this container.
  109.      */
  110.     public Dimension getPreferredSize () {
  111.         return new Dimension (320,140);
  112.     }
  113.    
  114.     /**
  115.      * Initialize the number of the field and fill them with default values.
  116.      * Dispaly the label of the Window.
  117.      */
  118.     public void init () {
  119.     }
  120.    
  121.     /**
  122.      * Proceed the execution of the action
  123.      * @return the result of the request.
  124.      * @param unUsed Not used
  125.      * @throws Exception if the command is not executed.
  126.      */
  127.     public String execute (String[] unUsed) throws Exception {
  128.         Object selectedPassenger[] = passengerList.getSelectedValues ();
  129.         String argv[] = new String[selectedPassenger.length + 1];
  130.         argv[0] = bookingInput.getText ();
  131.         System.arraycopy ( selectedPassenger, 0, argv, 1, selectedPassenger.length );
  132.         return action.execute ( argv );
  133.     }
  134.    
  135.     private JTextField bookingInput;
  136.     private JLabel bookingLabel;
  137.     private JButton identifyButton;
  138.     private JLabel passengerLabel;
  139.     private JList passengerList;
  140.     private JScrollPane passengerListScroll;
  141. }
  142.  

contact - link to this site