Bonjour,
je suis jeune étudiant, je suis bloqué dans mon application java Swing. Mon problème, j'ai utilise deux combo box l'un pour afficher les région et l'autre pour afficher les départements d'une région choisit dans le 1ére combo box.
EXEMPLE: Si l'utilisateur choisit dans le combo box Région= France
le combo box département remplit automatiquement =Paris
Marseille
etc...
Voici Mon code ( utilise netbeans):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
jComboBox1.addItem("----");
        String query1 = "SELECT nomregion FROM region";
       pst=getCon().prepareStatement(query1);
        ResultSet rs1 = pst.executeQuery();
 
        while(rs1.next()) {
           jComboBox1.addItem(rs1.getString("nomregion"));
        }
     jComboBox1.addActionListener(new ActionListener() {
 
         public void actionPerformed(ActionEvent ae) {
 
               String comboBox1Selected=jComboBox1.getSelectedItem().toString();
                try{
 
                    String query2 = "SELECT nomdepartement FROM departement, region where "+comboBox1Selected+"";
                    pst=getCon().prepareStatement(query2);
                    ResultSet rs2 = pst.executeQuery();
              jComboBox2.removeAllItems(); 
                    while(rs2.next()) {jComboBox2.addItem(rs2.getString("nomdepartement"));}
                    JOptionPane.showMessageDialog(null,"nomdepartement");
                }
                catch (SQLException ex1) {JOptionPane.showMessageDialog(null,"Erreur"+ex1.getLocalizedMessage()); ex1.printStackTrace();
                    return;}
 
 
            }
         });
Merci d'avance,