Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package base_de_donneé;
- import application.Parameter;
- import application.BDD;
- import com.sun.istack.internal.logging.Logger;
- import java.sql.*;
- import java.util.logging.Level;
- import javax.swing.JOptionPane;
- 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_DB , new Parameter().USERNAME_DB
- , new Parameter().PASSWORD_DB , new Parameter().IPHOST , new Parameter().PORT);
- initComponents();
- }
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jTextField1 = new javax.swing.JTextField();
- jButton1 = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- txt_pass = new javax.swing.JTextField();
- jLabel4 = new javax.swing.JLabel();
- txt_name = new javax.swing.JTextField();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jTextField1.setText("jTextField1");
- jButton1.setText("jButton1");
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- setName("administrateur"); // NOI18N
- getContentPane().setLayout(null);
- jLabel1.setFont(new java.awt.Font("Times New Roman", 3, 36)); // NOI18N
- jLabel1.setForeground(new java.awt.Color(0, 153, 204));
- jLabel1.setText("Login");
- getContentPane().add(jLabel1);
- jLabel1.setBounds(133, 11, 102, 42);
- jLabel2.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- jLabel2.setText("username : ");
- getContentPane().add(jLabel2);
- jLabel2.setBounds(20, 79, 94, 22);
- txt_pass.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- txt_pass.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_passActionPerformed(evt);
- }
- });
- getContentPane().add(txt_pass);
- txt_pass.setBounds(120, 150, 117, 22);
- jLabel4.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
- jLabel4.setText("Password :");
- getContentPane().add(jLabel4);
- jLabel4.setBounds(20, 145, 86, 22);
- txt_name.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
- txt_name.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txt_nameActionPerformed(evt);
- }
- });
- getContentPane().add(txt_name);
- txt_name.setBounds(120, 80, 117, 22);
- jButton2.setBackground(new java.awt.Color(255, 51, 51));
- jButton2.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
- jButton2.setText("fermer");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- getContentPane().add(jButton2);
- jButton2.setBounds(180, 220, 80, 30);
- jButton3.setBackground(new java.awt.Color(0, 51, 255));
- jButton3.setFont(new java.awt.Font("Times New Roman", 0, 18)); // NOI18N
- jButton3.setText("Login");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- getContentPane().add(jButton3);
- jButton3.setBounds(50, 220, 80, 30);
- pack();
- }// </editor-fold>
- private void txt_passActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void txt_nameActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- dispose();
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- rs = db.querySelectAll("utilisateur","username='" + txt_name.getText()
- +"'and Password='" + txt_pass.getText() + "'");
- try{
- while (rs.next()){
- username1 =rs.getString("usernama");
- 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 username ou password n'est pas incorrect");
- }else{
- if(hak.equals("directeur")){
- Principale h= new Principale();
- h.setVisible(true);
- this.dispose(); //si on a l'administrateur le pgm ouvrir la page principale
- }
- else{
- Cachier k=new Cachier(); // si en a chachier le pgm ouvrir Jframe cachier
- k.setVisible(true);
- this.dispose();
- }
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* 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);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Login().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField txt_name;
- private javax.swing.JTextField txt_pass;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement