J ai une page d identification qui comporte le choix d une fonction
dans une combobox, la saisie du nom dans un jTextField et la saisie du
mot de passe dans un jPasswordField.
Quand je clique sur jButton1, il faut allé vérifier les données dans la base de donnée et afficher la fenêtre correspondante.
Le problème est que je ne sais pas comment faire correspondre les champs de la table avec les composants SWING.
Voici le code :
Code :
package ihm;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
public class Background extends JFrame {
static public Background back;
static public Administrateur ad;
static public chefDesVentes che;
static public assistanteCommerciale ass;
public Background() {
initComponents();
setTitle("ComptoirFact");
setSize(550,550);
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Administrateur ad = new Administrateur();
chefDesVentes che = new chefDesVentes();
assistanteCommerciale ass = new assistanteCommerciale();
Connection conn = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:Comptoir","","");
System.out.println("Connexion établie avec Comptoir");
Statement s = conn.createStatement ();
s.executeQuery ("SELECT Employés.Nom, Employés.Mot de passe, Employés.Fonction FROM Employés ");
ResultSet rs = s.getResultSet ();
String mdp = rs.getString ("Mot de passe");
String nom= rs.getString("Nom");
String fct= rs.getString("Fonction");
if (fct == "Vice-Président")
ad.setVisible(true);
else if (fct == "Chef des ventes")
che.setVisible(true);
else if (fct == "Assistante commerciale")
ass.setVisible(true);
else if (fct == "Représentant(e)")
ass.setVisible(true);
else System.out.println("Erreur");
rs.close(); s.close();
}
catch(Exception e) {System.err.println("Pb avec SELECT");}
finally { if (conn != null) {
try {
conn.close(); System.out.println("Connexion terminée");}
catch(Exception e) {System.err.println ("Pb de fermeture de connexion ");}
}
}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
back = new Background();
back.setVisible(true);
}
});
}
private javax.swing.JMenuItem copyMenuItem;
private javax.swing.JMenuItem cutMenuItem;
private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JMenu editMenu;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JTextField jTextField1;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openMenuItem;
private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JMenuItem saveAsMenuItem;
private javax.swing.JMenuItem saveMenuItem;
}
Merci d'avance