Bonjour,
Je suis entrain de développer un mini application et je rencontre quelques difficultés au niveau des combobox. En effet, j'ai un combobox où j'ajoute les noms des projets et un autre où j'ajoute des usagers pour ce projet. Je ne vois pas comment mettre à jour le combobox des usagers en fonction de la sélection dans le combobox de projets.
Exemple si je choisi projet1 dans mon premier combobox le 2e combobox devrait afficher tous les personnes associé à ce projet.
Voici mon code :
Classes Projet :
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 public class Projet { private String nom; private ArrayList<Usager> listUsager; private float prix; private String description; public Projet(String nom,float prix) { this.nom=nom; this.prix=prix; listUsager = new ArrayList<Usager>(); } public void ajoutUsager(Usager u) { listUsager.add(u); } public void suppUsager(Usager u) { listUsager.remove(u); } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public ArrayList<Usager> getListUsager() { return listUsager; } public void setListUsager(ArrayList<Usager> listUsager) { this.listUsager = listUsager; } public float getPrix() { return prix; } public void setPrix(float prix) { this.prix = prix; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String toString() { String s=new String(); s=s+this.nom; return s; } }En espérant une réponse à mon problème...
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
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
161public Menu(){ this.setTitle("Tricount"); this.setSize(1200, 900); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t=new Tricount(); Nomprojet=new JLabel("Nom projet :"); listprojet=new JLabel("Liste projets :"); comboprojet=new JComboBox<>(); textprojet=new JTextField(); //textprojet.setActionCommand(""); titre=new JLabel("Bienvenu"); creerprojet=new JButton("Creer"); creerprojet.setActionCommand("Creer"); supprojet=new JButton("supprimer"); bilan=new JButton("Bilan Graphique"); equilibre=new JButton("Equilibre"); NomUsager=new JLabel("Nom usager :"); listUsager=new JLabel("Liste participant : "); comboUsager=new JComboBox<>(); textUsager=new JTextField(); ajoutUsager=new JButton("Ajouter"); suppUsager=new JButton("Supprimer"); typeDepense=new JLabel("Type depense"); typeDepense.setSize(10, 2); montant=new JLabel("Montant"); textdepense=new JTextField(); textmontant=new JTextField(); personneDepense=new JComboBox<>(); listDepense=new JComboBox<>(); ajouterDepense=new JButton("Ajouter depense"); ajoutUsager.addActionListener(this); suppUsager.addActionListener(this); comboprojet.addActionListener(this); comboUsager.addActionListener(this); creerprojet.addActionListener(this); comboprojet.addActionListener(this); supprojet.addActionListener(this); GridLayout gl = new GridLayout(1,1); GridLayout gl2 = new GridLayout(3,2); gl.setHgap(5); gl.setVgap(10); b=Box.createHorizontalBox(); b.add(Nomprojet); b.add(textprojet); b.add(listprojet); b.add(comboprojet); b.add(creerprojet); b.add(supprojet); b.add(equilibre); b.add(bilan); b1=Box.createHorizontalBox(); b1.add(NomUsager); b1.add(textUsager); textUsager.setMaximumSize(new Dimension(Integer.MAX_VALUE, textUsager.getMinimumSize().height)); b1.add(listUsager); b1.add(comboUsager); b1.add(ajoutUsager); b1.add(suppUsager); b2=Box.createHorizontalBox(); b2.add(typeDepense); b2.add(textdepense); b2.add(montant); b2.add(textmontant); b2.add(personneDepense); b2.add(ajouterDepense); bfinal = Box.createVerticalBox(); bfinal.add(b); bfinal.add(b1); bfinal.add(b2); //getContentPane().add(panelCreationProjet, BorderLayout.NORTH); getContentPane().add(bfinal,BorderLayout.NORTH); setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource()==this.creerprojet) { this.p=new Projet(this.textprojet.getText(), 500); this.t.ajoutProjet(p); this.comboprojet.addItem(p.getNom()); } if(e.getSource()==this.comboprojet) { if(this.comboprojet.getSelectedItem()==this.p.getNom()) { for(Usager u: p.getListUsager()) { this.comboUsager.addItem(u.getNom()); } } } if(e.getSource()==this.supprojet) { this.t.suppProjet(p); this.comboprojet.removeItem(p.getNom()); } if(e.getSource()==this.ajoutUsager) { this.u=new Usager(this.textUsager.getText(), 200); this.p.ajoutUsager(u); this.comboUsager.addItem(u.getNom()); for(Projet p: t.getListProjet()) { for(Usager u: p.getListUsager()) { System.out.println(p.getNom()+ " : "+u.getNom()); } } } if(e.getSource()==this.comboprojet) { if(comboprojet.getSelectedItem().equals(p.getNom())) { for(Usager u: p.getListUsager()) { this.comboUsager.addItem(u.getNom()); } } } if(e.getSource()==this.suppUsager) { this.p.suppUsager(u); this.comboUsager.removeItem(u.getNom()); } }







Répondre avec citation
Partager