Probleme ds Combobox swing

alias100 Messages postés 129 Date d'inscription jeudi 30 mars 2006 Statut Membre Dernière intervention 2 décembre 2012 - 9 mai 2007 à 10:02
kaloway Messages postés 358 Date d'inscription jeudi 24 octobre 2002 Statut Membre Dernière intervention 13 avril 2020 - 9 mai 2007 à 10:35
Bonjour,


Je suis débutant en swing et je trouve un problème dans le
JCombobox ds le rafraichissement ou l’ajout. J’explique mon problème


J’ai 3 classe :



<!--[if !supportLists]-->
1)     
<!--[endif]-->classe
Personne contient nom,prenom,age :




public




class

Personne
{









private


String

nom
;









private


String

prenom
;









private


String

age
;









public


Personne(String
nom,String prenom,String age)








{    









     


this

.
nom
=nom;









     


this

.
prenom
=prenom;









     


this

.
age
=age;








}









public


String
     GetNom(){

return



nom
;}








}



 





<!--[if !supportLists]-->
2)     
<!--[endif]-->classe
liste personne qui contient un attribut :




import


java.util.Vector;









public




class

Liste_Personne
{









      Vector

L
=

new

Vector();









      Liste_Personne()









      {









           
 Personne P1=

new

Personne(
"Fabbien"
,
"<st1:place w:st="on"><st1:city w:st="on">Pierre</st1:city></st1:place>"
,
"23"
);









           
 

L
.add(P1);









           
 Personne P2=

new

Personne(
"Fadoua"
,
"Micheal"
,
"30"
);









           
 

L
.add(P2);









     

}








}









 






<!--[if !supportLists]-->
3)     
<!--[endif]-->
une interface
GUI




import

java.awt.event.ActionEvent;









import


java.awt.event.ActionListener;









import


java.util.Iterator;









import


java.util.Vector;









import

javax.swing.*;









import


javax.swing.border.TitledBorder;









 







public




class

GUI

implements

ActionListener{









private


     JFrame
cadre
;









private


     JPanel
pane
,
pane_per
;









private


     JLabel
label
;









private


     JComboBox
list
;









private


 
    JButton

nouveau
,
Ajout
;








//









private


     JLabel
N
,
Pr
,
A
;









private


     TextField
T1
,
T2
,
T3
;








//









 






Vector <String> 

v
=

new

Vector<String>();








Liste_Personne
Lis
=

new

Liste_Personne();








Iterator
it
;










 








public

GUI()








{









           

cadre
=

new

JFrame(
"Personne"
);









           

cadre
.setSize(380,400);









           










           

pane
=

new

JPanel();









           

pane
.setSize(380,400);









     
  
  
 

label
=

new

JLabel(
"Les noms
des Personnes sont :"
);









     
     











     
    











     
   

it
=
Lis
.
L
.iterator();









           


while

(
it
.hasNext())









            {









                 
   Personne P= (Personne)
it
.next();









                 
  

v
.add(P.GetNom());









            }









                 
 










     
   

list
=

new

JComboBox(
v
);









     
   

pane
.add(
label
); 









     
   

pane
.add(
list
);









     
   

nouveau

  =

new

JButton(
"Nouveau
Personne"
);









     
   

nouveau
.addActionListener(

this

);









     
   










     
   

pane_per
=

new

JPanel();









           

pane_per
.setBorder(

new

TitledBorder(
" Nouvelle Personne"
));









           










     
   










     
   

N
=

new

JLabel(
"
Nom  "
);









     
   

Pr
=

new

JLabel(
" Prenom
"
);









           

A
=

new

JLabel(
" Age "
);









           

T1
=

new

JTextField (8);









           

T2
=

new

JTextField (8);









           

T3
=

new

JTextField (3);









           

Ajout
=

new

JButton(
" Ajouter "
);









           

Ajout
.addActionListener(

this

);









           

pane_per
.add(
N
);  
pane_per
.add(
T1
);









           

pane_per
.add(
Pr
); 
pane_per
.add(
T2
);









           

pane_per
.add(
A
);  
pane_per
.add(
T3
);









           

pane_per
.add(
Ajout
);









           

pane_per
.setVisible(

false

);     









           










     
   

pane
.add(
nouveau
);









     
   

pane
.add(
pane_per
);









     
   

cadre
.getContentPane().add(
pane
);









           

cadre
.setVisible(

true

);








}









 







     

/**









     
 

*



@param



args









     
 

*/









     


public




static




void

main(String[]
args) {









           

//

TODO

Auto-generated method stub









          GUI
inst=

new

GUI();









      }









 







     


public




void

actionPerformed(ActionEvent
arg0) {









           

//

TODO

Auto-generated method stub









           


if

(arg0.getSource()==
nouveau
)









            {









                 

pane_per
.setVisible(

true

);









            }









           


if

(arg0.getSource()==
Ajout
)









           

{









                  Personne NOUV=

new

Personne(
T1
.getText(),
T2
.getText(),
T3
.getText());









                 

Lis
.
L
.addElement(NOUV);









                 

list
.updateUI();           










            }









      }    








}









 







 






 





Le probleme reside lorsque j’ajoute une personne elle n’a pas ete
ajoute dans le JCombobox malgre j’ai fait list.updateUI





 




Merci pour vos aides



 

1 réponse

kaloway Messages postés 358 Date d'inscription jeudi 24 octobre 2002 Statut Membre Dernière intervention 13 avril 2020
9 mai 2007 à 10:35
list a comme vector v et non Lis.L
0
Rejoignez-nous