Advertisement
Guest User

sdfasd

a guest
Apr 27th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.59 KB | None | 0 0
  1. package accountmanager;
  2.  
  3. /**
  4.  *
  5.  * @author Rengi
  6.  */
  7.  
  8. import java.awt.Color;
  9. import java.sql.*;
  10. import javax.swing.*;
  11.  
  12. public class LogInScreen extends javax.swing.JFrame {
  13.  
  14.     Connection conn = null;
  15.     ResultSet rs = null;
  16.     PreparedStatement pst = null;
  17.     /**
  18.      * Creates new form MainScreen
  19.      */
  20.     public LogInScreen() {
  21.        
  22.         initComponents();
  23.         lblError.setVisible(false);
  24.        
  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.         jPanel1 = new javax.swing.JPanel();
  37.         tbxUsername = new javax.swing.JTextField();
  38.         lbxPass = new javax.swing.JLabel();
  39.         lblUsername = new javax.swing.JLabel();
  40.         btnSignIn = new javax.swing.JButton();
  41.         jButton1 = new javax.swing.JButton();
  42.         tbxPassword = new javax.swing.JPasswordField();
  43.         lblError = new javax.swing.JLabel();
  44.  
  45.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  46.         setTitle("Profile Manager Log-In");
  47.         addKeyListener(new java.awt.event.KeyAdapter() {
  48.             public void keyPressed(java.awt.event.KeyEvent evt) {
  49.                 formKeyPressed(evt);
  50.             }
  51.         });
  52.  
  53.         jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Login/Register"));
  54.  
  55.         lbxPass.setText("Password:");
  56.  
  57.         lblUsername.setText("Username:");
  58.  
  59.         btnSignIn.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rengi\\Documents\\NetBeansProjects\\AccountManager\\login.png")); // NOI18N
  60.         btnSignIn.setText("Sign In");
  61.         btnSignIn.addActionListener(new java.awt.event.ActionListener() {
  62.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  63.                 btnSignInActionPerformed(evt);
  64.             }
  65.         });
  66.  
  67.         jButton1.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rengi\\Documents\\NetBeansProjects\\AccountManager\\register.png")); // NOI18N
  68.         jButton1.setText("Register");
  69.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  70.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  71.                 jButton1ActionPerformed(evt);
  72.             }
  73.         });
  74.  
  75.         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  76.         jPanel1.setLayout(jPanel1Layout);
  77.         jPanel1Layout.setHorizontalGroup(
  78.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  79.             .addGroup(jPanel1Layout.createSequentialGroup()
  80.                 .addContainerGap()
  81.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  82.                     .addGroup(jPanel1Layout.createSequentialGroup()
  83.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  84.                             .addComponent(lblUsername)
  85.                             .addComponent(lbxPass))
  86.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  87.                         .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88.                             .addComponent(tbxPassword)
  89.                             .addComponent(tbxUsername)))
  90.                     .addGroup(jPanel1Layout.createSequentialGroup()
  91.                         .addComponent(jButton1)
  92.                         .addGap(104, 104, 104)
  93.                         .addComponent(btnSignIn)))
  94.                 .addContainerGap())
  95.         );
  96.         jPanel1Layout.setVerticalGroup(
  97.             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  98.             .addGroup(jPanel1Layout.createSequentialGroup()
  99.                 .addContainerGap()
  100.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  101.                     .addComponent(lblUsername)
  102.                     .addComponent(tbxUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  103.                 .addGap(18, 18, 18)
  104.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  105.                     .addComponent(lbxPass)
  106.                     .addComponent(tbxPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  107.                 .addGap(18, 18, 18)
  108.                 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  109.                     .addComponent(jButton1)
  110.                     .addComponent(btnSignIn))
  111.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  112.         );
  113.  
  114.         lblError.setForeground(new java.awt.Color(255, 102, 102));
  115.         lblError.setText(" The username or password is incorrect, please try again");
  116.  
  117.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  118.         getContentPane().setLayout(layout);
  119.         layout.setHorizontalGroup(
  120.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  121.             .addGroup(layout.createSequentialGroup()
  122.                 .addGap(17, 17, 17)
  123.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  124.                     .addComponent(lblError, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  125.                     .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  126.                 .addContainerGap(16, Short.MAX_VALUE))
  127.         );
  128.         layout.setVerticalGroup(
  129.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  130.             .addGroup(layout.createSequentialGroup()
  131.                 .addContainerGap()
  132.                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  133.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  134.                 .addComponent(lblError)
  135.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  136.         );
  137.  
  138.         pack();
  139.         setLocationRelativeTo(null);
  140.     }// </editor-fold>                        
  141.     Accounts ac = new Accounts();
  142.     public void getOwnerId(){
  143.         try{
  144.            
  145.             Accounts.ownerid = rs.getString("userid");
  146.             rs = pst.executeQuery();
  147.            
  148.         }catch(Exception e){
  149.             System.out.println(e);
  150.         }
  151.     }
  152.     private void btnSignInActionPerformed(java.awt.event.ActionEvent evt) {                                          
  153.         conn = MySqlConnect.ConnectDB();
  154.         String Sql = "SELECT * FROM login where username=? and password=?";
  155.         try{
  156.             pst = conn.prepareStatement(Sql);
  157.             pst.setString(1, tbxUsername.getText());
  158.             pst.setString(2, tbxPassword.getText());
  159.             rs = pst.executeQuery();
  160.             if(rs.next()){
  161.                 getOwnerId();
  162.                
  163.                 setVisible(false);
  164.                 Accounts ac = new Accounts();
  165.                 ac.setVisible(true);
  166.                 ac.send2Console(new Color(145, 223, 255),"userid: " + Accounts.ownerid + " has logged in.");
  167.                
  168.             }else{
  169.                 lblError.setVisible(true);
  170.             }
  171.         }
  172.         catch(Exception e){
  173.             JOptionPane.showMessageDialog(null, e);
  174.         }
  175.     }                                        
  176.  
  177.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  178.         // TODO add your handling code here:
  179.         setVisible(false);
  180.         Register rg = new Register();
  181.         rg.setVisible(true);
  182.        
  183.     }                                        
  184.  
  185.     private void formKeyPressed(java.awt.event.KeyEvent evt) {                                
  186.         // TODO add your handling code here:
  187.     }                              
  188.  
  189.     /**
  190.      * @param args the command line arguments
  191.      */
  192.     public static void main(String args[]) {
  193.         /* Set the Nimbus look and feel */
  194.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  195.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  196.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  197.          */
  198.         try {
  199.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  200.                 if ("Windows".equals(info.getName())) {
  201.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  202.                     break;
  203.                 }
  204.             }
  205.         } catch (ClassNotFoundException ex) {
  206.             java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  207.         } catch (InstantiationException ex) {
  208.             java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  209.         } catch (IllegalAccessException ex) {
  210.             java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  211.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  212.             java.util.logging.Logger.getLogger(LogInScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  213.         }
  214.         //</editor-fold>
  215.         //</editor-fold>
  216.  
  217.         /* Create and display the form */
  218.         java.awt.EventQueue.invokeLater(new Runnable() {
  219.             public void run() {
  220.                 new LogInScreen().setVisible(true);
  221.             }
  222.         });
  223.     }
  224.  
  225.     // Variables declaration - do not modify                    
  226.     private javax.swing.JButton btnSignIn;
  227.     private javax.swing.JButton jButton1;
  228.     private javax.swing.JPanel jPanel1;
  229.     private javax.swing.JLabel lblError;
  230.     private javax.swing.JLabel lblUsername;
  231.     private javax.swing.JLabel lbxPass;
  232.     private javax.swing.JPasswordField tbxPassword;
  233.     private javax.swing.JTextField tbxUsername;
  234.     // End of variables declaration                  
  235. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement