Advertisement
Myranda

Untitled

Apr 2nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.87 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 StaffLogin extends javax.swing.JFrame {
  15.  
  16.     SingletonController ctr = SingletonController.getInstance();
  17.  
  18.     public StaffLogin() {
  19.         initComponents();
  20.         this.setLocationRelativeTo(null);
  21.         this.setTitle("Staff Login");
  22.     }
  23.  
  24.     /**
  25.      * This method is called from within the constructor to initialize the form.
  26.      * WARNING: Do NOT modify this code. The content of this method is always
  27.      * regenerated by the Form Editor.
  28.      */
  29.     @SuppressWarnings("unchecked")
  30.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  31.     private void initComponents() {
  32.  
  33.         jLabel1 = new javax.swing.JLabel();
  34.         jLabel2 = new javax.swing.JLabel();
  35.         jLabel3 = new javax.swing.JLabel();
  36.         txtPassword = new javax.swing.JPasswordField();
  37.         txtUsername = new java.awt.TextField();
  38.         btnLogin = new javax.swing.JButton();
  39.         btnHome = new javax.swing.JButton();
  40.         jLabel4 = new javax.swing.JLabel();
  41.  
  42.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  43.  
  44.         jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
  45.         jLabel1.setText("Staff Login");
  46.  
  47.         jLabel2.setText("Username:");
  48.  
  49.         jLabel3.setText("Password:");
  50.  
  51.         btnLogin.setText("Login to Staff System");
  52.         btnLogin.addActionListener(new java.awt.event.ActionListener() {
  53.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  54.                 btnLoginActionPerformed(evt);
  55.             }
  56.         });
  57.  
  58.         btnHome.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/home-icon.png"))); // NOI18N
  59.         btnHome.addActionListener(new java.awt.event.ActionListener() {
  60.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  61.                 btnHomeActionPerformed(evt);
  62.             }
  63.         });
  64.  
  65.         jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  66.         jLabel4.setText("Please enter your username and password below");
  67.  
  68.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  69.         getContentPane().setLayout(layout);
  70.         layout.setHorizontalGroup(
  71.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  72.             .addGroup(layout.createSequentialGroup()
  73.                 .addContainerGap()
  74.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  75.                     .addGroup(layout.createSequentialGroup()
  76.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  77.                             .addGroup(layout.createSequentialGroup()
  78.                                 .addComponent(jLabel1)
  79.                                 .addGap(0, 0, Short.MAX_VALUE))
  80.                             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  81.                                 .addGap(0, 0, Short.MAX_VALUE)
  82.                                 .addComponent(jLabel4)))
  83.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  84.                         .addComponent(btnHome, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))
  85.                     .addGroup(layout.createSequentialGroup()
  86.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  87.                             .addComponent(jLabel3)
  88.                             .addComponent(jLabel2))
  89.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  90.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  91.                             .addComponent(txtPassword)
  92.                             .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
  93.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  94.                         .addComponent(btnLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
  95.                         .addGap(0, 0, Short.MAX_VALUE)))
  96.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  97.         );
  98.         layout.setVerticalGroup(
  99.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  100.             .addGroup(layout.createSequentialGroup()
  101.                 .addContainerGap()
  102.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  103.                     .addGroup(layout.createSequentialGroup()
  104.                         .addComponent(btnHome)
  105.                         .addGap(15, 15, 15))
  106.                     .addGroup(layout.createSequentialGroup()
  107.                         .addComponent(jLabel1)
  108.                         .addGap(11, 11, 11)
  109.                         .addComponent(jLabel4)
  110.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
  111.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  112.                     .addGroup(layout.createSequentialGroup()
  113.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  114.                             .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  115.                             .addComponent(jLabel2))
  116.                         .addGap(10, 10, 10)
  117.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  118.                             .addComponent(jLabel3)
  119.                             .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  120.                     .addComponent(btnLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
  121.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  122.         );
  123.  
  124.         pack();
  125.     }// </editor-fold>                        
  126.  
  127.     private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                        
  128.         //gather username and password and make request to login
  129.         String username = txtUsername.getText();
  130.         String password = txtPassword.getText();
  131.         int request = ctr.authenticateUser(username, password);
  132.  
  133.         //return the access level of user to confirm they are staff
  134.         if (request == 1) {
  135.             JOptionPane.showMessageDialog(null, "Login Successful");
  136.             this.setVisible(false);
  137.             ctr.openGUI(btnLogin.getText());
  138.             //if access is not authorized, deny entry
  139.         } else {
  140.             JOptionPane.showMessageDialog(null, "Login Unsuccessful");
  141.         }
  142.     }                                        
  143.  
  144.     private void btnHomeActionPerformed(java.awt.event.ActionEvent evt) {                                        
  145.         //open the main menu
  146.         ctr.openGUI("Main Menu");
  147.         this.setVisible(false);
  148.     }                                      
  149.  
  150.     /**
  151.      * @param args the command line arguments
  152.      */
  153.     public static void main(String args[]) {
  154.         /* Set the Nimbus look and feel */
  155.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  156.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  157.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  158.          */
  159.         try {
  160.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  161.                 if ("Nimbus".equals(info.getName())) {
  162.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  163.                     break;
  164.                 }
  165.             }
  166.         } catch (ClassNotFoundException ex) {
  167.             java.util.logging.Logger.getLogger(StaffLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  168.         } catch (InstantiationException ex) {
  169.             java.util.logging.Logger.getLogger(StaffLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  170.         } catch (IllegalAccessException ex) {
  171.             java.util.logging.Logger.getLogger(StaffLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  172.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  173.             java.util.logging.Logger.getLogger(StaffLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  174.         }
  175.         //</editor-fold>
  176.         //</editor-fold>
  177.         //</editor-fold>
  178.         //</editor-fold>
  179.         //</editor-fold>
  180.         //</editor-fold>
  181.         //</editor-fold>
  182.         //</editor-fold>
  183.  
  184.         /* Create and display the form */
  185.         java.awt.EventQueue.invokeLater(new Runnable() {
  186.             public void run() {
  187.                 new StaffLogin().setVisible(true);
  188.             }
  189.         });
  190.     }
  191.  
  192.     // Variables declaration - do not modify                    
  193.     private javax.swing.JButton btnHome;
  194.     private javax.swing.JButton btnLogin;
  195.     private javax.swing.JLabel jLabel1;
  196.     private javax.swing.JLabel jLabel2;
  197.     private javax.swing.JLabel jLabel3;
  198.     private javax.swing.JLabel jLabel4;
  199.     private javax.swing.JPasswordField txtPassword;
  200.     private java.awt.TextField txtUsername;
  201.     // End of variables declaration                  
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement