Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.14 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 dl3185j
  13.  */
  14. public class Register extends javax.swing.JFrame {
  15.  
  16.     UserLogin login = new UserLogin();
  17.     SingletonController ctr = SingletonController.getInstance();
  18.  
  19.     /**
  20.      * Creates new form Register
  21.      */
  22.     public Register() {
  23.         initComponents();
  24.         this.setLocationRelativeTo(null);
  25.     }
  26.  
  27.     /**
  28.      * This method is called from within the constructor to initialize the form.
  29.      * WARNING: Do NOT modify this code. The content of this method is always
  30.      * regenerated by the Form Editor.
  31.      */
  32.     @SuppressWarnings("unchecked")
  33.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  34.     private void initComponents() {
  35.  
  36.         jLabel1 = new javax.swing.JLabel();
  37.         jLabel2 = new javax.swing.JLabel();
  38.         jLabel3 = new javax.swing.JLabel();
  39.         txtName = new javax.swing.JTextField();
  40.         txtUserName = new javax.swing.JTextField();
  41.         txtPassword = new javax.swing.JTextField();
  42.         btnRegister = new javax.swing.JButton();
  43.         btnCancel = new javax.swing.JButton();
  44.         txtAddress = new javax.swing.JTextField();
  45.         jLabel4 = new javax.swing.JLabel();
  46.         txtEmail = new javax.swing.JTextField();
  47.         jLabel5 = new javax.swing.JLabel();
  48.         jLabel6 = new javax.swing.JLabel();
  49.  
  50.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  51.         setName("Register"); // NOI18N
  52.  
  53.         jLabel1.setText("FULL NAME: ");
  54.  
  55.         jLabel2.setText("USERNAME:");
  56.  
  57.         jLabel3.setText("PASSWORD:");
  58.  
  59.         btnRegister.setText("Register");
  60.         btnRegister.addActionListener(new java.awt.event.ActionListener() {
  61.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  62.                 btnRegisterActionPerformed(evt);
  63.             }
  64.         });
  65.  
  66.         btnCancel.setText("Cancel");
  67.         btnCancel.addActionListener(new java.awt.event.ActionListener() {
  68.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  69.                 btnCancelActionPerformed(evt);
  70.             }
  71.         });
  72.  
  73.         jLabel4.setText("ADDRESS:");
  74.  
  75.         jLabel5.setText("EMAIL:");
  76.  
  77.         jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  78.         jLabel6.setText("Please enter your details below");
  79.  
  80.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  81.         getContentPane().setLayout(layout);
  82.         layout.setHorizontalGroup(
  83.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84.             .addGroup(layout.createSequentialGroup()
  85.                 .addContainerGap()
  86.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  87.                     .addGroup(layout.createSequentialGroup()
  88.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  89.                             .addComponent(jLabel3)
  90.                             .addComponent(jLabel2))
  91.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  92.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93.                             .addComponent(txtUserName)
  94.                             .addComponent(txtPassword)))
  95.                     .addGroup(layout.createSequentialGroup()
  96.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  97.                             .addComponent(jLabel4)
  98.                             .addComponent(jLabel5)
  99.                             .addComponent(jLabel1))
  100.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  101.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  102.                             .addComponent(txtEmail)
  103.                             .addComponent(txtAddress)
  104.                             .addComponent(txtName)))
  105.                     .addGroup(layout.createSequentialGroup()
  106.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  107.                             .addGroup(layout.createSequentialGroup()
  108.                                 .addGap(21, 21, 21)
  109.                                 .addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
  110.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  111.                                 .addComponent(btnRegister, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
  112.                             .addComponent(jLabel6))
  113.                         .addGap(0, 29, Short.MAX_VALUE)))
  114.                 .addContainerGap())
  115.         );
  116.         layout.setVerticalGroup(
  117.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  118.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  119.                 .addContainerGap()
  120.                 .addComponent(jLabel6)
  121.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
  122.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  123.                     .addComponent(jLabel1)
  124.                     .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  125.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  126.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  127.                     .addComponent(txtAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  128.                     .addComponent(jLabel4))
  129.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  130.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  131.                     .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  132.                     .addComponent(jLabel5))
  133.                 .addGap(18, 18, 18)
  134.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  135.                     .addComponent(jLabel2)
  136.                     .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  137.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  138.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  139.                     .addComponent(jLabel3)
  140.                     .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  141.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  142.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  143.                     .addComponent(btnCancel)
  144.                     .addComponent(btnRegister))
  145.                 .addContainerGap())
  146.         );
  147.  
  148.         pack();
  149.     }// </editor-fold>                        
  150.  
  151.     private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {                                          
  152.         //opens the login GUI
  153.         this.setVisible(false);
  154.         login.setVisible(true);
  155.     }                                        
  156.  
  157.     private void btnRegisterActionPerformed(java.awt.event.ActionEvent evt) {                                            
  158.         //gather details and add user to databse
  159.         String name = txtName.getText();
  160.         String address = txtAddress.getText();
  161.         String email = txtEmail.getText();
  162.         String user = txtUserName.getText();
  163.         String pass = txtPassword.getText();
  164.         boolean result = ctr.addUser(name, user, pass, email, address);
  165.  
  166.         //alert user of results
  167.         if (result == true) {
  168.             JOptionPane.showMessageDialog(null, "You are registered! You may now login");
  169.             this.setVisible(false);
  170.             ctr.openGUI("Checkout");
  171.         } else {
  172.             JOptionPane.showMessageDialog(null, "ERROR: Username is already taken, please choose another");
  173.         }
  174.  
  175.     }                                          
  176.  
  177.     /**
  178.      * @param args the command line arguments
  179.      */
  180.     public static void main(String args[]) {
  181.         /* Set the Nimbus look and feel */
  182.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  183.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  184.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  185.          */
  186.         try {
  187.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  188.                 if ("Nimbus".equals(info.getName())) {
  189.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  190.                     break;
  191.                 }
  192.             }
  193.         } catch (ClassNotFoundException ex) {
  194.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  195.         } catch (InstantiationException ex) {
  196.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  197.         } catch (IllegalAccessException ex) {
  198.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  199.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  200.             java.util.logging.Logger.getLogger(Register.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  201.         }
  202.         //</editor-fold>
  203.  
  204.         /* Create and display the form */
  205.         java.awt.EventQueue.invokeLater(new Runnable() {
  206.             public void run() {
  207.                 new Register().setVisible(true);
  208.             }
  209.         });
  210.     }
  211.  
  212.     // Variables declaration - do not modify                    
  213.     private javax.swing.JButton btnCancel;
  214.     private javax.swing.JButton btnRegister;
  215.     private javax.swing.JLabel jLabel1;
  216.     private javax.swing.JLabel jLabel2;
  217.     private javax.swing.JLabel jLabel3;
  218.     private javax.swing.JLabel jLabel4;
  219.     private javax.swing.JLabel jLabel5;
  220.     private javax.swing.JLabel jLabel6;
  221.     private javax.swing.JTextField txtAddress;
  222.     private javax.swing.JTextField txtEmail;
  223.     private javax.swing.JTextField txtName;
  224.     private javax.swing.JTextField txtPassword;
  225.     private javax.swing.JTextField txtUserName;
  226.     // End of variables declaration                  
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement