Probléme de gestion des evenements pour deux JComboBox
Mon problémé se situe dans le fait que je veux récuperer deux attributs de deux JComboBox pour les utiliser dans le constructeur d'un Jpanel.
Mais j'arrive pas à les récuperer et le Jpanel ne s'affiche pas.
Voici le code:
Code:
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
|
ViewPanel dessin;
Instances m_instances;
private JComboBox liste_attX;
private JComboBox liste_attY;
private int index1=-1;
private int index2=-1;
public GridView(String s,int i,Instances inst){
super (" Interface graphique :Fuzzy Grid");
m_instances=new Instances(inst);
Container inter=buildContentPane();
Container interieurB = getContentPane();
interieurB.setLayout(new BorderLayout(5, 5));
interieurB.add( inter, BorderLayout.NORTH);
addWindowListener(this);
liste_attX.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
liste_attX = (JComboBox) e.getSource();
String ClassNameX = (String) liste_attX.getSelectedItem();
index1 = m_instances.attribute(ClassNameX).index();
}
});
liste_attY.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
liste_attY = (JComboBox) e.getSource();
String ClassNameY = (String) liste_attY.getSelectedItem();
index2 = m_instances.attribute(ClassNameY).index();
}
});
if((index1!=-1) && (index2!=-1)){
dessin=new ViewPanel(inst,index1,index2);
interieurB.add( dessin, BorderLayout.CENTER);
dessin.setVisible(true);
}
}
private JPanel buildContentPane(){
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.setBackground(Color.WHITE);
Object[] items=new Object[m_instances.numAttributes()-1];
for(int k=0;k<m_instances.numAttributes()-1;k++){
items[k]=m_instances.attribute(k).name();
}
JLabel labelX = new JLabel("L'attribut de l'axe X\n");
panel.add(labelX);
liste_attX=new JComboBox(items);
panel.add(liste_attX);
JLabel labelY = new JLabel("L'attribut de l'axe Y\n");
panel.add(labelY);
liste_attY=new JComboBox(items);
panel.add(liste_attY);
return panel;
} |
SVP,aider moi en signalant l'erreur ou proposer une autre maniére de faire.
Merci.