Myranda

Untitled

Apr 2nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.34 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package coachtravelling;
  7.  
  8. import javax.swing.JOptionPane;
  9.  
  10. /**
  11.  *
  12.  * @author Danny
  13.  */
  14. public class TripEnquiry extends javax.swing.JFrame {
  15.  
  16.     //get instance of controller
  17.     SingletonController ctr = SingletonController.getInstance();
  18.  
  19.     public TripEnquiry() {
  20.         initComponents();
  21.         this.setLocationRelativeTo(null);
  22.         this.setTitle("Make Enquiry");
  23.     }
  24.  
  25.     @SuppressWarnings("unchecked")
  26.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  27.     private void initComponents() {
  28.  
  29.         jLabel1 = new javax.swing.JLabel();
  30.         jScrollPane1 = new javax.swing.JScrollPane();
  31.         txtEnquiry = new javax.swing.JTextArea();
  32.         btnSubmit = new javax.swing.JButton();
  33.         btnBack = new javax.swing.JButton();
  34.         jLabel2 = new javax.swing.JLabel();
  35.         txtName = new javax.swing.JTextField();
  36.  
  37.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  38.  
  39.         jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  40.         jLabel1.setText("Please enter your enquiry here:");
  41.  
  42.         txtEnquiry.setColumns(20);
  43.         txtEnquiry.setRows(5);
  44.         jScrollPane1.setViewportView(txtEnquiry);
  45.  
  46.         btnSubmit.setText("SUBMIT");
  47.         btnSubmit.addActionListener(new java.awt.event.ActionListener() {
  48.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  49.                 btnSubmitActionPerformed(evt);
  50.             }
  51.         });
  52.  
  53.         btnBack.setText("BACK");
  54.         btnBack.addActionListener(new java.awt.event.ActionListener() {
  55.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  56.                 btnBackActionPerformed(evt);
  57.             }
  58.         });
  59.  
  60.         jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  61.         jLabel2.setText("Please enter your name:");
  62.  
  63.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  64.         getContentPane().setLayout(layout);
  65.         layout.setHorizontalGroup(
  66.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  67.             .addGroup(layout.createSequentialGroup()
  68.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  69.                     .addGroup(layout.createSequentialGroup()
  70.                         .addContainerGap()
  71.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  72.                             .addComponent(jScrollPane1)
  73.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  74.                                 .addGap(0, 4, Short.MAX_VALUE)
  75.                                 .addComponent(btnBack, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
  76.                                 .addGap(18, 18, 18)
  77.                                 .addComponent(btnSubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))))
  78.                     .addGroup(layout.createSequentialGroup()
  79.                         .addGap(20, 20, 20)
  80.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  81.                             .addComponent(jLabel1)
  82.                             .addGroup(layout.createSequentialGroup()
  83.                                 .addComponent(jLabel2)
  84.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  85.                                 .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
  86.                         .addGap(0, 0, Short.MAX_VALUE)))
  87.                 .addContainerGap())
  88.         );
  89.         layout.setVerticalGroup(
  90.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  91.             .addGroup(layout.createSequentialGroup()
  92.                 .addContainerGap()
  93.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  94.                     .addComponent(jLabel2)
  95.                     .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  96.                 .addGap(24, 24, 24)
  97.                 .addComponent(jLabel1)
  98.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  99.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
  100.                 .addGap(12, 12, 12)
  101.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  102.                     .addComponent(btnSubmit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  103.                     .addComponent(btnBack))
  104.                 .addContainerGap())
  105.         );
  106.  
  107.         pack();
  108.     }// </editor-fold>                        
  109.  
  110.     private void btnBackActionPerformed(java.awt.event.ActionEvent evt) {                                        
  111.         //open enquiry gui
  112.         this.setVisible(false);
  113.         ctr.openGUI("Make an Enquiry");
  114.     }                                      
  115.  
  116.     private void btnSubmitActionPerformed(java.awt.event.ActionEvent evt) {                                          
  117.         //get name and enquiry of user
  118.         String name = txtName.getText();
  119.         String enquiry = txtEnquiry.getText();
  120.  
  121.         //check values are not empty
  122.         if (name.isEmpty() || enquiry.isEmpty()) {
  123.             JOptionPane.showMessageDialog(null, "ERROR: Please enter details in both fields");
  124.             return;
  125.         }
  126.  
  127.         //add the enquiry to the database and confirm success
  128.         int result = ctr.makeEnquiry(name, enquiry);
  129.         JOptionPane.showMessageDialog(null, "Your enqiry has been made! Reference : " + result);
  130.         this.setVisible(false);
  131.         ctr.openGUI("Make an Enquiry");
  132.     }                                        
  133.  
  134.     /**
  135.      * @param args the command line arguments
  136.      */
  137.     public static void main(String args[]) {
  138.         /* Set the Nimbus look and feel */
  139.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  140.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  141.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  142.          */
  143.         try {
  144.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  145.                 if ("Nimbus".equals(info.getName())) {
  146.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  147.                     break;
  148.                 }
  149.             }
  150.         } catch (ClassNotFoundException ex) {
  151.             java.util.logging.Logger.getLogger(TripEnquiry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  152.         } catch (InstantiationException ex) {
  153.             java.util.logging.Logger.getLogger(TripEnquiry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  154.         } catch (IllegalAccessException ex) {
  155.             java.util.logging.Logger.getLogger(TripEnquiry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  156.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  157.             java.util.logging.Logger.getLogger(TripEnquiry.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  158.         }
  159.         //</editor-fold>
  160.  
  161.         /* Create and display the form */
  162.         java.awt.EventQueue.invokeLater(new Runnable() {
  163.             public void run() {
  164.                 new TripEnquiry().setVisible(true);
  165.             }
  166.         });
  167.     }
  168.  
  169.     // Variables declaration - do not modify                    
  170.     private javax.swing.JButton btnBack;
  171.     private javax.swing.JButton btnSubmit;
  172.     private javax.swing.JLabel jLabel1;
  173.     private javax.swing.JLabel jLabel2;
  174.     private javax.swing.JScrollPane jScrollPane1;
  175.     private javax.swing.JTextArea txtEnquiry;
  176.     private javax.swing.JTextField txtName;
  177.     // End of variables declaration                  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment