booking system

  1. /*
  2.  * ReservePanel.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.functions.Reserve;
  8. import reservation.CustomDialog;
  9.  
  10. import javax.swing.*;
  11. import java.awt.event.*;
  12. import java.awt.Dimension;
  13.  
  14. /**
  15.  * This class hold Reserve structure. This object allows to reserve to one flight one or many persons by calling the method <CODE>reserve</CODE> in {@link reservation.system.FlightSystem}.
  16.  * It use a GUI that contains a form with the several field to fill.
  17.  * @author Texier Mathieu and Frederic Bidon
  18.  */
  19. public class ReservePanel extends Panels {
  20.    
  21.     /** Creates new form ReservePanel */
  22.     public ReservePanel () {
  23.         action = new Reserve ();
  24.        
  25.         selectLabel = new JLabel ();
  26.         flightSelect = new JComboBox ();
  27.         passengerLabel = new JLabel ();
  28.         nameSelect = new JComboBox ();
  29.         addButton = new JButton ();
  30.         selectLabel.setText ("Select");
  31.         add (selectLabel);
  32.        
  33.         flightSelect.setMaximumSize (new Dimension (100, 20));
  34.         add (flightSelect);
  35.        
  36.         passengerLabel.setText ("Passenger");
  37.         add (passengerLabel);
  38.        
  39.         nameSelect.setEditable (true);
  40.         add (nameSelect);
  41.        
  42.         addButton.setText ("Add");
  43.         add (addButton);
  44.         addButton.addActionListener (new ActionListener () {
  45.             public void actionPerformed (ActionEvent evt) {
  46.                 nameSelect.addItem ( nameSelect.getSelectedItem ());
  47.                 nameSelect.getEditor ().setItem ("");
  48.             }
  49.         });
  50.     }
  51.    
  52.     /**
  53.      * Initialize the number of the field and fill them with default values.
  54.      * Dispaly the label of the Window.
  55.      */
  56.     public void init () {
  57.         try {
  58.             String [] retValue = fs.getFlightList ();
  59.             if (retValue != null) {
  60.                 for (int i=0;i< retValue.length;i++) {
  61.                     flightSelect.addItem (retValue[i]);
  62.                 }
  63.             }
  64.         } catch (Exception e) {
  65.             CustomDialog.alert (e);
  66.         }
  67.     }
  68.    
  69.     /**
  70.      * Causes this container to lay out its components.
  71.      */
  72.     public void doLayout () {
  73.         selectLabel.setBounds (20, 20, 40, 20);
  74.         flightSelect.setBounds (110, 20, 140, 20);
  75.         passengerLabel.setBounds (20, 60, 80, 20);
  76.         nameSelect.setBounds (110, 60, 70, 20);
  77.         addButton.setBounds (190, 60, 60, 20);
  78.     }
  79.    
  80.     /**
  81.      * Set the size of the panel
  82.      * @return an instance of Dimension that represents the minimum size of this container.
  83.      */
  84.     public Dimension getMinimumSize () {
  85.         return new Dimension (300,100);
  86.     }
  87.    
  88.     /**
  89.      * Set the size of the panel
  90.      * @return an instance of Dimension that represents the preferred size of this container.
  91.      */
  92.     public Dimension getPreferredSize () {
  93.         return new Dimension (300,100);
  94.     }
  95.    
  96.     /**
  97.      * Proceed the execution of the action
  98.      * @return the result of the request.
  99.      * @param unUsed not used
  100.      * @throws Exception if the command is not executed.
  101.      */
  102.     public String execute (String[] unUsed) throws Exception {
  103.         int itemNumber = nameSelect.getItemCount ();
  104.         String arg[] = new String[itemNumber+1];
  105.         arg[0] = (String) flightSelect.getSelectedItem ();
  106.         for (int i=0;i<itemNumber;i++) {
  107.             arg[i+1] = (String) nameSelect.getItemAt (i);
  108.         }
  109.         return action.execute (arg);
  110.     }
  111.    
  112.     private JButton addButton;
  113.     private JComboBox flightSelect;
  114.     private JComboBox nameSelect;
  115.     private JLabel passengerLabel;
  116.     private JLabel selectLabel;
  117. }
  118.  

contact - link to this site