Bonjour a tous,
je suis entrain de développer une application java sur Eclipse IDE.j'ai rencontré un problème lorsque j'appelle une nouvelle fenêtre lors d'un clic d'un élément d'un combobox.Il m'affiche toujours une fenêtre vide.Si j’exécute la classe contenant la nouvelle fenêtre ça va bien.le code est ci dessous:
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
// "Choice" le nom de la classe que je veux appeler
import java.awt.event.*;
 
import java.io.File;
import java.util.List;
 
import javax.swing.*;
import javax.xml.bind.*;
 
public class choice  extends JFrame{
 
    public static final String FILE_PATH ="sous_command.xml";
 
    public static void main(String[] args) throws Exception {
 
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
    	File file = new File(FILE_PATH);
                ComboBoxModel model = new DefaultComboBoxModel(getNames(file).toArray());
                final JComboBox cbox = new JComboBox(model);
                cbox.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent e) {
                        command1 cmd = (command1)cbox.getSelectedItem();
 
                    	String x=cbox.getSelectedItem().toString();
   switch(x)
   {
   case("hclust"):
	   System.out.println("hclust");
   break;
 
   }
                        //System.out.println(cmd.getLabel());
                    }
                });
 
               // JOptionPane.showMessageDialog( null,cbox);
                //ZDialog zd = new ZDialog(null, "Coucou ", true);
        	  JFrame f= new JFrame("hi");
        		f.setSize(300,400);
        		f.add(cbox);
        		f.pack();
        		f.setVisible(true);
            }
        });
    }
 
    private static List<command1> getNames(File file) {
        List<command1> names = null;
        try {
            JAXBContext context = JAXBContext.newInstance(GenericLabel.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            GenericLabel genericName = (GenericLabel)unmarshaller
                    .unmarshal(file);
 
 
          names = genericName.getcmd();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
 
        return names;
    }
 
}
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
//"AddAlgorithms" c'est ma classe principale
package Essai;
import java.awt.Container;
 
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
 
 
public class AddAlgorithms extends JFrame implements ActionListener {
	private Container c;
	private DefaultComboBoxModel comboModel;
	private JComboBox combo;
 
 
	public AddAlgorithms() {
		super("Add Algorithms");
		initialize();
	}
 
	private void initialize() {
		c = getContentPane();
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		JButton btn= new JButton("Suivant");
 
		comboModel = new DefaultComboBoxModel();
		comboModel.addElement("Java");
		comboModel.addElement("R");
		comboModel.addElement("C++");
		comboModel.addElement("C");
		combo = new JComboBox(comboModel);
		btn.addActionListener(this);
 
 
		JPanel jp = new JPanel();
		jp.setPreferredSize(new Dimension(320, 200));
		jp.add(combo);
		jp.add(btn);
 
		c.add(jp);
	}
 
	public static void main(String[] args) {
		AddAlgorithms select = new AddAlgorithms();
		select.pack();
		select.setVisible(true);
	}
 
	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
	      this.dispose();
          choice c2 =new choice();
          c2.setVisible(true);
 
	}
}
Quelqu'un peut m'aider s'il vous plait?