package base_de_donnee; import application.BDD; import application.Parameter; import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; /** * * @author USER */ public class Login extends javax.swing.JFrame { //déclaration ResultSet rs; BDD db; String username1, password1, hak; public Login() { db= new BDD(new Parameter().HOST_BD,new Parameter().USERNAME_DB,new Parameter().PASSWORD_DB,new Parameter().IPHOST, new Parameter().PORT); initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); txt_password = new javax.swing.JTextField(); txt_username = new javax.swing.JTextField(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jLabel = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); getContentPane().setLayout(null); jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 48)); // NOI18N jLabel1.setForeground(new java.awt.Color(0, 204, 255)); jLabel1.setText("Login"); getContentPane().add(jLabel1); jLabel1.setBounds(168, 20, 121, 67); jLabel2.setFont(new java.awt.Font("Times New Roman", 3, 18)); // NOI18N jLabel2.setText("Password :"); getContentPane().add(jLabel2); jLabel2.setBounds(40, 170, 90, 22); jLabel3.setFont(new java.awt.Font("Times New Roman", 3, 18)); // NOI18N jLabel3.setText("Username:"); getContentPane().add(jLabel3); jLabel3.setBounds(43, 120, 90, 20); txt_password.setFont(new java.awt.Font("Times New Roman", 3, 14)); // NOI18N txt_password.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txt_passwordActionPerformed(evt); } }); getContentPane().add(txt_password); txt_password.setBounds(170, 160, 130, 30); txt_username.setFont(new java.awt.Font("Times New Roman", 3, 14)); // NOI18N txt_username.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txt_usernameActionPerformed(evt); } }); getContentPane().add(txt_username); txt_username.setBounds(170, 110, 130, 30); jButton1.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N jButton1.setText("Fermer"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1); jButton1.setBounds(180, 260, 90, 30); jButton2.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N jButton2.setText("Login"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); getContentPane().add(jButton2); jButton2.setBounds(60, 260, 73, 31); jLabel.setForeground(new java.awt.Color(255, 0, 0)); getContentPane().add(jLabel); jLabel.setBounds(170, 140, 130, 20); pack(); }// //GEN-END:initComponents private void txt_passwordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_passwordActionPerformed // TODO add your handling code here: }//GEN-LAST:event_txt_passwordActionPerformed private void txt_usernameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txt_usernameActionPerformed // TODO add your handling code here: }//GEN-LAST:event_txt_usernameActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed dispose(); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed rs= db.querySelectAll("utilisateur","username='"+txt_username.getText()+"'and password='"+txt_password.getText()+"'"); try{ while(rs.next()){ username1=rs.getString("username"); password1=rs.getString("password"); hak=rs.getString("type"); } } catch(SQLException ex){ Logger.getLogger(Login.class.getName()).log(Level.SEVERE,null,ex); } if(username1==null && password1 == null){ JOptionPane.showMessageDialog(this,"le nom utilisateur ou le mots de pass est incorrect"); }else { if(hak.equals("directeur")){ Principale h = new Principale(); h.setVisible(true); this.dispose();//si en Directeur:le programme affiche Principale }else{ Cachier k = new Cachier();//si en Cachier:le programme affiche jframe cachier k.setVisible(true); this.dispose();//fonction dispose pour fermer } } }//GEN-LAST:event_jButton2ActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ // /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // // /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Login().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JTextField txt_password; private javax.swing.JTextField txt_username; // End of variables declaration//GEN-END:variables }