Bonsoir,

Je fais face à un petit problème.

J'ai implémenté un mini projet me permettant, selon la saisie d'un avion et son vol associé de savoir s'il peut ou non faire le vol, fonction de la distance et du carburant dont il dispose.

Le fait étant que ce n'est pas friendly user en mode console.

J'ai donc voulu tester le wysiwyg de NetBeans et me faire une petite interface rapide...

Mais je bloque dès le départ :/

J'ai créé une jComboBox... mais je n'arrive pas à la lier avec ma liste d'avion, une ArrayList renseignée.

J'ai tenté ceci :
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
161
162
163
164
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
/*
 * i_trafficAerien.java
 *
 * Created on 21 mars 2009, 19:05:05
 */
 
package trafficaerien;
 
import java.util.ArrayList;
 
/**
 *
 * @author Deallyra
 */
public class i_trafficAerien extends javax.swing.JDialog {
 
    /** Creates new form i_trafficAerien */
    public i_trafficAerien(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
 
        jCB_ListeAvion = new javax.swing.JComboBox();
        jLBL_Avion = new javax.swing.JLabel();
        jLBL_Resultat = new javax.swing.JLabel();
        jLBL_Titre = new javax.swing.JLabel();
        jLBL_Resultat_avant = new javax.swing.JLabel();
        jCB_ListeVol = new javax.swing.JComboBox();
        jLBL_Vol = new javax.swing.JLabel();
        jLBL_resultat_apres = new javax.swing.JLabel();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Traffic Aerien");
 
        jCB_ListeAvion.setModel(null);
        for(int i=0; i <= desAvions.size(); i++){
            jCB_Avion.addItem(desAvions.get(i).getMarque());
        }
        jCB_ListeAvion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCB_ListeAvionActionPerformed(evt);
            }
        });
 
        jLBL_Avion.setText("Choisir un Avion :");
 
        jLBL_Resultat.setText("ne peut pas");
 
        jLBL_Titre.setFont(new java.awt.Font("Monotype Corsiva", 1, 24));
        jLBL_Titre.setForeground(java.awt.Color.blue);
        jLBL_Titre.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLBL_Titre.setText("Traffic Aerien");
 
        jLBL_Resultat_avant.setText("Cet avion");
 
        jCB_ListeVol.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
 
        jLBL_Vol.setText("Choisir un Vol :");
 
        jLBL_resultat_apres.setText("faire ce vol.");
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(125, Short.MAX_VALUE)
                .addComponent(jLBL_Resultat_avant)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLBL_Resultat)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLBL_resultat_apres)
                .addGap(103, 103, 103))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLBL_Vol, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLBL_Avion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jCB_ListeVol, javax.swing.GroupLayout.Alignment.LEADING, 0, 243, Short.MAX_VALUE)
                    .addComponent(jCB_ListeAvion, javax.swing.GroupLayout.Alignment.LEADING, 0, 243, Short.MAX_VALUE))
                .addGap(49, 49, 49))
            .addComponent(jLBL_Titre, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jLBL_Titre, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCB_ListeAvion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLBL_Avion))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCB_ListeVol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLBL_Vol))
                .addGap(31, 31, 31)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLBL_Resultat_avant)
                    .addComponent(jLBL_Resultat, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLBL_resultat_apres))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
 
        pack();
    }// </editor-fold>
 
    private void jCB_ListeAvionActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
}
 
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                i_trafficAerien dialog = new i_trafficAerien(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                    public void windowOpening(java.awt.event.WindowEvent e) {
                        Avion a1 = new Avion("Airbus A340-300", 295, 129300, 55600, 100, 13000, 140640,140640);
                        Avion a2 = new Avion("Boeing 747-400", 524, 178756, 218134, 200, 10668, 216840,216840);
                        Avion a3 = new Avion("Cessna 150", 2, 480, 246, 50, 3855, 140,140);
                        desAvions.add(a1);
                        desAvions.add(a2);
                        desAvions.add(a3);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JComboBox jCB_ListeAvion;
    private javax.swing.JComboBox jCB_ListeVol;
    private javax.swing.JLabel jLBL_Avion;
    private javax.swing.JLabel jLBL_Resultat;
    private javax.swing.JLabel jLBL_Resultat_avant;
    private javax.swing.JLabel jLBL_Titre;
    private javax.swing.JLabel jLBL_Vol;
    private javax.swing.JLabel jLBL_resultat_apres;
    // End of variables declaration
    static protected ArrayList<Avion> desAvions = new ArrayList<Avion>();
}
Merci à vous,