Bonjour,
J'ai un problème avec l'interface graphique de mon projet. J'ai une JComboBox et je souhaiterais que dès qu'il y a un changement dans la combobox les changements soit répercutées sur une autre combobox, pour cela j'utilise un actionPerform sur la première combo.
Problème : Dans la méthode ActionPerform j'utilise une méthode d'une autre classe, j'ai donc l'objet de l'autre classe en tant qu'attribut et je l'instancie dès la première ligne de mon constructeur. Mais dès que je lance l'application j'ai une NULLPOINTEREXCEPTION car il ne reconnais pas l'instanciation fais au préalable.
Voici le code de mon constructeur :
Dans la méthode initComponents() il y a l'ajout de l'actionPerformed au listener :
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 public SimulatorGui() throws ClassNotFoundException, SQLException { this.d = new Data(); this.g = new Graph(); initComponents(); pool = Executors.newCachedThreadPool(); prop = new Properties(); fileProp = new File("settings"); visitorsProportions = new LinkedList<>(); tasks = new LinkedList<>(); extract.setVisible(false); int row = 6; for (VisitorFactory.VisitorType type : VisitorFactory.VisitorType.values()) { GridBagConstraints labelConstraint = new GridBagConstraints(); labelConstraint.gridx = 0; labelConstraint.gridy = row++; visitorsPanel.add(new JLabel(type.toString()), labelConstraint); GridBagConstraints spinnerConstraints = new GridBagConstraints(); spinnerConstraints.gridx = 1; spinnerConstraints.gridy = labelConstraint.gridy; JSpinner spin = new JSpinner(new SpinnerNumberModel(0.0d, 0.0d, 100.0d, 0.5d)); spin.addChangeListener(this); visitorsProportions.add(spin); visitorsPanel.add(spin, spinnerConstraints); } visitorsProportions.iterator().next().setEnabled(false); algoChoice.removeAllItems(); for (Algorithm algo : Algorithm.values()) { algoChoice.addItem(algo); } simulationset.removeAllItems(); for (Object s : d.ExtractAllSimulationGroup()) { simulationset.addItem(s); } runset.removeAllItems(); try { Object[] o = d.ExtractAllSimulation(/*simulationset.getSelectedItem().toString()*/); for (int i=0; i<o.length-1; i++){ runset.addItem(o[i]); } }catch(SQLException e) { Logger.getLogger(SimulatorGui.class.getName()).log(Level.SEVERE, null, e); } loadProperties(); pack(); }
et voici le code de mon actionPerformed :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 simulationset.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { simulationsetActionPerformed(evt); } });
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 private void simulationsetItemStateChanged(java.awt.event.ItemEvent evt) { runset.removeAllItems(); try { Object[] o = d.ExtractAllSimulation(/*simulationset.getSelectedItem().toString()*/); for (int i=0; i<o.length-1; i++){ runset.addItem(o[i]); } }catch(SQLException e) { Logger.getLogger(SimulatorGui.class.getName()).log(Level.SEVERE, null, e); } }
Merci d'avance de votre aide précieuse !
Partager