Bonsoir tout le monde;
j'ai un petit problème que je n'arrive pas à résoudre.
j'ai une jFrame avec des jlabel et des radiobuton :
Nom : developper.png
Affichages : 185
Taille : 3,6 Ko

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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 
import java.awt.Color;
import javax.swing.JLabel;
 
 
public class Form1 extends javax.swing.JFrame {
 
 
    public void activer(JLabel lbl){
        lbl.setForeground(new Color(50, 200, 50));
    }
    public void inactiver(JLabel lbl){
        lbl.setForeground(new Color(200, 50, 50));
    }
 
    public Form1() {
        initComponents();
        this.setSize(265, 200);
        this.setLocation(200, 200);
 
    }
 
 
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {
 
        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        rbt_1_3_7 = new javax.swing.JRadioButton();
        rbt_1_2 = new javax.swing.JRadioButton();
        rbt_2_4_6 = new javax.swing.JRadioButton();
        rbt_4_6_7_8 = new javax.swing.JRadioButton();
        rbt_1_6_7 = new javax.swing.JRadioButton();
        rbt_4_5_8 = new javax.swing.JRadioButton();
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(null);
 
        jLabel1.setText("jLabel1");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(180, 20, 60, 17);
 
        jLabel2.setText("jLabel2");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(180, 40, 60, 17);
 
        jLabel3.setText("jLabel3");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(180, 60, 60, 17);
 
        jLabel4.setText("jLabel4");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(180, 80, 60, 17);
 
        jLabel5.setText("jLabel5");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(180, 100, 60, 17);
 
        jLabel6.setText("jLabel6");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(180, 120, 60, 17);
 
        jLabel7.setText("jLabel7");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(180, 140, 60, 17);
 
        jLabel8.setText("jLabel8");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(180, 160, 60, 17);
 
        buttonGroup1.add(rbt_1_3_7);
        rbt_1_3_7.setText("rbt_1_3_7");
        rbt_1_3_7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbt_1_3_7ActionPerformed(evt);
            }
        });
        getContentPane().add(rbt_1_3_7);
        rbt_1_3_7.setBounds(20, 10, 120, 26);
 
        buttonGroup1.add(rbt_1_2);
        rbt_1_2.setText("rbt_1_2");
        rbt_1_2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbt_1_2ActionPerformed(evt);
            }
        });
        getContentPane().add(rbt_1_2);
        rbt_1_2.setBounds(20, 40, 120, 26);
 
        buttonGroup1.add(rbt_2_4_6);
        rbt_2_4_6.setText("rbt_2_4_6");
        rbt_2_4_6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rbt_2_4_6ActionPerformed(evt);
            }
        });
        getContentPane().add(rbt_2_4_6);
        rbt_2_4_6.setBounds(20, 70, 120, 26);
 
        buttonGroup1.add(rbt_4_6_7_8);
        rbt_4_6_7_8.setText("rbt_4_6_7_8");
        getContentPane().add(rbt_4_6_7_8);
        rbt_4_6_7_8.setBounds(20, 100, 120, 26);
 
        buttonGroup1.add(rbt_1_6_7);
        rbt_1_6_7.setText("rbt_1_6_7");
        getContentPane().add(rbt_1_6_7);
        rbt_1_6_7.setBounds(20, 130, 120, 26);
 
        buttonGroup1.add(rbt_4_5_8);
        rbt_4_5_8.setText("rbt_4_5_8");
        getContentPane().add(rbt_4_5_8);
        rbt_4_5_8.setBounds(20, 160, 120, 26);
 
        pack();
    }// </editor-fold>                        
 
    private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
        JLabel mesLabel[]={jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8};
        for(int i=0;i<8;i++){
            inactiver(mesLabel[i]);
        }
    }                                 
 
    private void rbt_1_3_7ActionPerformed(java.awt.event.ActionEvent evt) {                                          
        JLabel mesLabel[]={jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8};
        for(int i=0;i<8;i++){
            if(i==0 || i==2 || i==6){
                activer(mesLabel[i]);
            }else{
                inactiver(mesLabel[i]);
            }
 
        }
    }                                         
 
    private void rbt_1_2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        JLabel mesLabel[]={jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8};
        for(int i=0;i<8;i++){
            if(i==0 || i==1){
                activer(mesLabel[i]);
            }else{
                inactiver(mesLabel[i]);
            }
 
        }
    }                                       
 
    private void rbt_2_4_6ActionPerformed(java.awt.event.ActionEvent evt) {                                          
         JLabel mesLabel[]={jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8};
        for(int i=0;i<8;i++){
            if(i==1 || i==3 || i==5){
                activer(mesLabel[i]);
            }else{
                inactiver(mesLabel[i]);
            }
 
        }
    }                                         
 
    public static void main(String args[]) {
       //*****************************************
 
       //*****************************************
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Form1().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify                     
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JRadioButton rbt_1_2;
    private javax.swing.JRadioButton rbt_1_3_7;
    private javax.swing.JRadioButton rbt_1_6_7;
    private javax.swing.JRadioButton rbt_2_4_6;
    private javax.swing.JRadioButton rbt_4_5_8;
    private javax.swing.JRadioButton rbt_4_6_7_8;
    // End of variables declaration                   
}
comment créer un tableau " JLabel mesLabel[]={jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6,jLabel7,jLabel8};" une seule fois sans à devoir le créer pour chaque radiobutton?
Merci