Advertisement
youmna_dou

Untitled

May 17th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.02 KB | None | 0 0
  1.  
  2. package base_de_donneé;
  3.  
  4. import application.Parameter;
  5. import application.BDD;
  6. import com.sun.istack.internal.logging.Logger;
  7. import java.sql.*;
  8. import java.util.logging.Level;
  9. import javax.swing.JOptionPane;
  10.  
  11.  
  12.  
  13. public class Login extends javax.swing.JFrame {
  14. //déclaration
  15.     ResultSet rs ;
  16.     BDD db ;
  17.     String username1 , password1 ,hak ;
  18.    
  19.    
  20.     public Login() {
  21.         db=new BDD(new Parameter().HOST_DB , new Parameter().USERNAME_DB
  22.          , new Parameter().PASSWORD_DB , new Parameter().IPHOST , new Parameter().PORT);
  23.         initComponents();
  24.     }
  25.  
  26.    
  27.     @SuppressWarnings("unchecked")
  28.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  29.     private void initComponents() {
  30.  
  31.         jTextField1 = new javax.swing.JTextField();
  32.         jButton1 = new javax.swing.JButton();
  33.         jLabel1 = new javax.swing.JLabel();
  34.         jLabel2 = new javax.swing.JLabel();
  35.         txt_pass = new javax.swing.JTextField();
  36.         jLabel4 = new javax.swing.JLabel();
  37.         txt_name = new javax.swing.JTextField();
  38.         jButton2 = new javax.swing.JButton();
  39.         jButton3 = new javax.swing.JButton();
  40.  
  41.         jTextField1.setText("jTextField1");
  42.  
  43.         jButton1.setText("jButton1");
  44.  
  45.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  46.         setName("administrateur"); // NOI18N
  47.         getContentPane().setLayout(null);
  48.  
  49.         jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 36)); // NOI18N
  50.         jLabel1.setForeground(new java.awt.Color(0, 153, 204));
  51.         jLabel1.setText("Login");
  52.         getContentPane().add(jLabel1);
  53.         jLabel1.setBounds(133, 11, 102, 42);
  54.  
  55.         jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  56.         jLabel2.setText("username : ");
  57.         getContentPane().add(jLabel2);
  58.         jLabel2.setBounds(20, 79, 94, 22);
  59.  
  60.         txt_pass.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  61.         txt_pass.addActionListener(new java.awt.event.ActionListener() {
  62.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  63.                 txt_passActionPerformed(evt);
  64.             }
  65.         });
  66.         getContentPane().add(txt_pass);
  67.         txt_pass.setBounds(120, 150, 117, 22);
  68.  
  69.         jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  70.         jLabel4.setText("Password :");
  71.         getContentPane().add(jLabel4);
  72.         jLabel4.setBounds(20, 145, 86, 22);
  73.  
  74.         txt_name.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  75.         txt_name.addActionListener(new java.awt.event.ActionListener() {
  76.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  77.                 txt_nameActionPerformed(evt);
  78.             }
  79.         });
  80.         getContentPane().add(txt_name);
  81.         txt_name.setBounds(120, 80, 117, 22);
  82.  
  83.         jButton2.setBackground(new java.awt.Color(255, 51, 51));
  84.         jButton2.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
  85.         jButton2.setText("fermer");
  86.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  87.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  88.                 jButton2ActionPerformed(evt);
  89.             }
  90.         });
  91.         getContentPane().add(jButton2);
  92.         jButton2.setBounds(180, 220, 80, 30);
  93.  
  94.         jButton3.setBackground(new java.awt.Color(0, 51, 255));
  95.         jButton3.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
  96.         jButton3.setText("Login");
  97.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  98.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  99.                 jButton3ActionPerformed(evt);
  100.             }
  101.         });
  102.         getContentPane().add(jButton3);
  103.         jButton3.setBounds(50, 220, 80, 30);
  104.  
  105.         pack();
  106.     }// </editor-fold>                        
  107.  
  108.     private void txt_passActionPerformed(java.awt.event.ActionEvent evt) {                                        
  109.         // TODO add your handling code here:
  110.     }                                        
  111.  
  112.     private void txt_nameActionPerformed(java.awt.event.ActionEvent evt) {                                        
  113.         // TODO add your handling code here:
  114.     }                                        
  115.  
  116.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  117.        dispose();
  118.     }                                        
  119.  
  120.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  121.         rs = db.querySelectAll("utilisateur","username='" + txt_name.getText()
  122.         +"'and Password='" + txt_pass.getText() + "'");
  123.         try{
  124.         while (rs.next()){
  125.             username1 =rs.getString("usernama");
  126.             password1 =rs.getString("password");
  127.             hak = rs.getString("type");
  128.            
  129.         }
  130.         }catch (SQLException ex ){
  131.         Logger.getLogger(Login.class.getName()).log(Level.SEVERE , null , ex);
  132.         }
  133.        
  134.         if (username1 == null && password1 == null ){
  135.           JOptionPane.showMessageDialog (this, "le username ou password n'est pas incorrect");
  136.         }else{
  137.             if(hak.equals("directeur")){
  138.             Principale h= new Principale();
  139.             h.setVisible(true);
  140.             this.dispose(); //si on a l'administrateur  le pgm ouvrir la page principale
  141.            
  142.             }
  143.             else{
  144.            Cachier k=new Cachier(); // si en a chachier  le pgm ouvrir Jframe cachier
  145.             k.setVisible(true);
  146.             this.dispose();
  147.                    
  148.            
  149.             }
  150.         }
  151.    
  152.     }                                        
  153.  
  154.     /**
  155.      * @param args the command line arguments
  156.      */
  157.     public static void main(String args[]) {
  158.         /* Set the Nimbus look and feel */
  159.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  160.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  161.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  162.          */
  163.         try {
  164.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  165.                 if ("Nimbus".equals(info.getName())) {
  166.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  167.                     break;
  168.                 }
  169.             }
  170.         } catch (ClassNotFoundException ex) {
  171.             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  172.         } catch (InstantiationException ex) {
  173.             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  174.         } catch (IllegalAccessException ex) {
  175.             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  176.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  177.             java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  178.         }
  179.         //</editor-fold>
  180.  
  181.         /* Create and display the form */
  182.         java.awt.EventQueue.invokeLater(new Runnable() {
  183.             public void run() {
  184.                 new Login().setVisible(true);
  185.             }
  186.         });
  187.     }
  188.        
  189.    
  190.  
  191.     // Variables declaration - do not modify                    
  192.     private javax.swing.JButton jButton1;
  193.     private javax.swing.JButton jButton2;
  194.     private javax.swing.JButton jButton3;
  195.     private javax.swing.JLabel jLabel1;
  196.     private javax.swing.JLabel jLabel2;
  197.     private javax.swing.JLabel jLabel4;
  198.     private javax.swing.JTextField jTextField1;
  199.     private javax.swing.JTextField txt_name;
  200.     private javax.swing.JTextField txt_pass;
  201.     // End of variables declaration                  
  202.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement