1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
| package application;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class login extends javax.swing.JFrame {
ResultSet rs ;
DBB db ;
String username1,password1,hak;
public login() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
TXT2 = new javax.swing.JTextField();
TXT1 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(null);
jLabel1.setFont(new java.awt.Font("Sylfaen", 1, 36)); // NOI18N
jLabel1.setForeground(new java.awt.Color(102, 102, 255));
jLabel1.setText("Login");
getContentPane().add(jLabel1);
jLabel1.setBounds(147, 37, 179, 48);
jLabel2.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
jLabel2.setText("username");
getContentPane().add(jLabel2);
jLabel2.setBounds(32, 98, 103, 22);
jLabel3.setFont(new java.awt.Font("Tahoma", 3, 18)); // NOI18N
jLabel3.setText("Password ");
getContentPane().add(jLabel3);
jLabel3.setBounds(32, 155, 103, 37);
TXT2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
TXT2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
TXT2ActionPerformed(evt);
}
});
getContentPane().add(TXT2);
TXT2.setBounds(170, 160, 140, 29);
TXT1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
getContentPane().add(TXT1);
TXT1.setBounds(172, 96, 140, 29);
jButton2.setFont(new java.awt.Font("Tahoma", 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, 230, 100, 31);
pack();
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
rs = db.QselectAll("Untitled","username='"+TXT1.getText()+"'and password='"+TXT2.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 non utilisateur ou le mots pass est inncorrect");
}else{
if(hak.equals("admin")){
principal h =new principal();
h.setVisible(true);
this.dispose();
}else{
principal2 k = new principal2();
k.setVisible(true);
this.dispose();
}
}
}
private void TXT2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @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 <a href="http://download.oracle.com/javase/tu...feel/plaf.html" target="_blank">http://download.oracle.com/javase/tu...feel/plaf.html</a>
*/
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>
//</editor-fold>
//</editor-fold>
//</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.JTextField TXT1;
private javax.swing.JTextField TXT2;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
// End of variables declaration
private static class Principal {
public Principal() {
}
private void setVisible(boolean b) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
} |
Partager