Bonjour a tous,voila, j'ai une combobox qui liste des mode_de_paiement :
avec un bouton a coté qui ouvre une popup contenant une combobox, et 1 bouton qui permet d'ajouter un mode_de_paiement :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public JComboBox getJComboBox_paiment_famclients() { if (jComboBox_paiment_famclients == null) { jComboBox_paiment_famclients = new JComboBox(); jComboBox_paiment_famclients.setBounds(new Rectangle(162, 184, 120, 24)); } return jComboBox_paiment_famclients;
combo :
bouton ajouter :
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
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 private JComboBox getJComboBox_mdp_client() { if (jComboBox_mdp_client == null) { jComboBox_mdp_client = new JComboBox(); jComboBox_mdp_client.setBounds(new Rectangle(14, 80, 123, 23)); jComboBox_mdp_client.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed() String valeur =(String) jComboBox_mdp_client.getSelectedItem(); jTextField_designation_paiement_famclients.setText(valeur); { Statement instruction = null; Connection connexion = null; ResultSet resultat = null; try { Class.forName("com.mysql.jdbc.Driver"); connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root",""); instruction = connexion.createStatement(); resultat = instruction.executeQuery("SELECT code_mdp FROM mode_de_paiement WHERE lib_mdp = '"+valeur+"'" ); resultat.next(); { jTextField_code_paiement_famclients.setText((resultat.getString("code_mdp"))); } } catch (ClassNotFoundException ex) { JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage()); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Connexion impossible:" +ex.getMessage()); } finally { try { if(connexion !=null) connexion.close(); if(instruction !=null) instruction.close(); if (connexion !=null) connexion.close(); } catch (SQLException ex) { ex.printStackTrace(); } } } } }); jComboBox_mdp_client.getSelectedItem(); } return jComboBox_mdp_client;
qui en meme temps reactualise mon popup et donc ma combo quand je clique dessus.
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
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 private JButton getJButton_ajouter_famclients() { if (jButton_ajouter_famclients == null) { jButton_ajouter_famclients = new JButton(); jButton_ajouter_famclients.setBounds(new Rectangle(148, 80, 92, 24)); jButton_ajouter_famclients.setText("Ajouter"); jButton_ajouter_famclients.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e){ { Statement instruction = null; Connection connexion = null; ResultSet resultat = null; try { Class.forName("com.mysql.jdbc.Driver"); connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root",""); instruction = connexion.createStatement(); resultat = instruction.executeQuery("SELECT lib_mdp FROM mode_de_paiement" ); instruction.executeUpdate("INSERT INTO mode_de_paiement(lib_mdp) VALUES('"+jTextField_designation_paiement_famclients.getText()+"')"); resultat = instruction.executeQuery("SELECT lib_mdp FROM mode_de_paiement" ); jFrame_paiement_famclients.setVisible(false); paiement_famclients pai= new paiement_famclients(); pai.getJFrame_paiement_famclients(); } catch (ClassNotFoundException ex) { JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage()); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Connexion impossible:" + ex.getMessage()); } finally { try { if(connexion !=null) connexion.close(); if(instruction !=null) instruction.close(); if (connexion !=null) connexion.close(); } catch (SQLException ex) { ex.printStackTrace(); } } } } }); } return jButton_ajouter_famclients; }
mes 2 combos sont remplies de la meme maniere ( elles doivent donc contenir la meme chose) :
le Probleme est que quand j'ajoute un paiement dans la combo de mon popup l'actualisation se passe bien mais , quand je ferme mon popup la combo de ma page principal est restée telle qu'elle etait alors que la base de données a bien changée, j'ai deja essayer uptadeUI mais rien a faire, auriez vous une idée pour actualiser quand je clique sur mon bouton ajouter svp??
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
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 { Statement instruction = null; Connection connexion = null; ResultSet resultat = null; try { Class.forName("com.mysql.jdbc.Driver"); connexion = DriverManager.getConnection("jdbc:mysql://localhost/gescom2","root",""); instruction = connexion.createStatement(); resultat = instruction.executeQuery("SELECT lib_mdp FROM mode_de_paiement" ); while(resultat.next()) { jComboBox_mdp_client.addItem((resultat.getString("lib_mdp"))); } } catch (ClassNotFoundException ex) { JOptionPane.showMessageDialog(null,"Classe introuvable" + ex.getMessage()); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Connexion impossible:" +ex.getMessage()); } finally { try { if(connexion !=null) connexion.close(); if(instruction !=null) instruction.close(); if (connexion !=null) connexion.close(); } catch (SQLException ex) { ex.printStackTrace(); } } } return jPanel_paiement_famclients; }
Partager