Bonjour à tous !
Je cherche à créer un formulaire dont le thème est défini par un bouton avant. Il y a 4 formulaires dans mon CardLayout, mais certains champs sont communs.
J'ai essayé plusieurs moyens pour obtenir à la validation du formulaire les données, mais j'avoue j'arrive pô !
Mon dernier essai, avoir tous les champs en variables et les mettre sur chaque formulaire où ils sont, mais on dirait qu'un élément ne peut pas être à 2 endroits en même temps...
Code java : 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
 
public class PopupInformations extends JFrame implements ActionListener {
    Bouton cg, sng, spin, mtt;
    DoubleTextField gain;
    MontantTextField limite;
    IntTextField stDev, multiRatio, duree, itm;
    ArrayList<MontantTextField> echelleGains;
    JPanel formulaire;
    public PopupInformations() {
        gain = new DoubleTextField();
        limite = new MontantTextField();
        MontantTextField limiteCG = limite;
        stDev = new IntTextField();
        multiRatio = new IntTextField();
        duree = new IntTextField();
        itm = new IntTextField();
        echelleGains = new ArrayList<>();
 
        Color background = ClassMain.global().background();
        Color foreground = ClassMain.global().foreground();
        setSize(800, 400);
        JPanel pan = new JPanel();
        setContentPane(pan);
        pan.setBackground(background);
        pan.setLayout(new BoxLayout(pan, BoxLayout.PAGE_AXIS));
 
        //TITRE
        JPanel panTitre = new JPanel();
        JLabel titre = new JLabel(Textes.POPUPINFORMATIONS_titre());
        panTitre.add(titre);
        pan.add(panTitre);
 
        //zone ajout
        JPanel panAjout = new JPanel();
        panAjout.setLayout(new BoxLayout(panAjout, BoxLayout.PAGE_AXIS));
        panAjout.setBackground(background);
        //titre
        JPanel panTitreAjout = new JPanel();
        JLabel titreAjout = new JLabel(Textes.POPUPINFORMATIONS_titreAjout());
        panTitreAjout.add(titreAjout);
        pan.add(panTitreAjout);
        //choix jeu
        JPanel panChoixJeu = new JPanel();
        panChoixJeu.setBackground(background);
        panChoixJeu.setLayout(new BoxLayout(panChoixJeu, BoxLayout.LINE_AXIS));
        cg = new Bouton(Textes.GLOBAL_cashgame());
        cg.setFocusPainted(false);
        cg.setBackground(foreground);
        cg.setForeground(background);
        sng = new Bouton(Textes.GLOBAL_sng());
        sng.setFocusPainted(false);
        spin = new Bouton(Textes.GLOBAL_spin());
        spin.setFocusPainted(false);
        mtt = new Bouton(Textes.GLOBAL_mtt());
        mtt.setFocusPainted(false);
        ButtonGroup group = new ButtonGroup();
        group.add(cg);
        group.add(spin);
        group.add(sng);
        group.add(mtt);
        panChoixJeu.add(cg);
        panChoixJeu.add(spin);
        panChoixJeu.add(sng);
        panChoixJeu.add(mtt);
        panAjout.add(panChoixJeu);
        //formulaires
        formulaire = new JPanel(new CardLayout());
        formulaire.setBorder(BorderFactory.createBevelBorder(1));
            // formulaire vide
        JPanel panVide = new JPanel();
        formulaire.add(panVide, "vide");
            //formulaire cg
        JPanel panCG = new JPanel();
        JPanel _limiteCG = new JPanel();
        _limiteCG.add(new JLabel(Textes.INFO_bb()));
        _limiteCG.add(limiteCG);
        panCG.add(_limiteCG);
        JPanel _evCG = new JPanel();
        _evCG.add(new JLabel(Textes.INFO_evCash()));
        _evCG.add(gain);
        panCG.add(_evCG);
        JPanel _stdevCG = new JPanel();
        _stdevCG.add(new JLabel(Textes.INFO_stdev()));
        _stdevCG.add(stDev);
        panCG.add(_stdevCG);
        JPanel _hhhoursCG = new JPanel();
        _hhhoursCG.add(new JLabel(Textes.INFO_handsHourCG()));
        _hhhoursCG.add(duree);
        panCG.add(_hhhoursCG);
        JPanel _multiRatioCG = new JPanel();
        _multiRatioCG.add(new JLabel(Textes.INFO_multiRatio()));
        _multiRatioCG.add(multiRatio);
        panCG.add(_multiRatioCG);
        formulaire.add(panCG, "cg");
        cg.addActionListener(this);
        //formulaire spin
        JPanel panSpin = new JPanel();
        JPanel _limiteSpin = new JPanel();
        _limiteSpin.add(new JLabel(Textes.INFO_buyIn()));
        _limiteSpin.add(limite);
        panSpin.add(_limiteSpin);
        JPanel _evSpin = new JPanel();
        _evSpin.add(new JLabel(Textes.INFO_evSpin()));
        _evSpin.add(gain);
        panSpin.add(_evSpin);
        JButton gainsSpin = new JButton(Textes.INFO_echelleGains());
        panSpin.add(gainsSpin);
        JPanel _hhhoursSpin = new JPanel();
        _hhhoursSpin.add(new JLabel(Textes.INFO_durationTourney()));
        _hhhoursSpin.add(duree);
        panSpin.add(_hhhoursSpin);
        JPanel _multiRatioSpin = new JPanel();
        _multiRatioSpin.add(new JLabel(Textes.INFO_multiRatio()));
        _multiRatioSpin.add(multiRatio);
        panSpin.add(_multiRatioSpin);
        formulaire.add(panSpin, "spin");
        spin.addActionListener(this);
            //formulaire sng
        JPanel panSnG = new JPanel();
        JPanel _limiteSnG = new JPanel();
        _limiteSnG.add(new JLabel(Textes.INFO_buyIn()));
        _limiteSnG.add(limite);
        panSnG.add(_limiteSnG);
        JPanel _evSnG = new JPanel();
        _evSnG.add(new JLabel(Textes.INFO_evTourney()));
        _evSnG.add(gain);
        panSnG.add(_evSnG);
        JPanel _itmSnG = new JPanel();
        _itmSnG.add(new JLabel(Textes.INFO_itm()));
        _itmSnG.add(itm);
        panSnG.add(_itmSnG);
        JButton gainsSnG = new JButton(Textes.INFO_echelleGains());
        panSnG.add(gainsSnG);
        JPanel _hhhoursSnG = new JPanel();
        _hhhoursSnG.add(new JLabel(Textes.INFO_durationTourney()));
        _hhhoursSnG.add(duree);
        panSnG.add(_hhhoursSnG);
        JPanel _multiRatioSnG = new JPanel();
        _multiRatioSnG.add(new JLabel(Textes.INFO_multiRatio()));
        _multiRatioSnG.add(multiRatio);
        panSnG.add(_multiRatioSnG);
        formulaire.add(panSnG, "sng");
        sng.addActionListener(this);
            //formulaire mtt
        JPanel panMTT = new JPanel();
        JPanel _limiteMTT = new JPanel();
        _limiteMTT.add(new JLabel(Textes.INFO_buyIn()));
        _limiteMTT.add(limite);
        panMTT.add(_limiteMTT);
        JPanel _evMTT = new JPanel();
        _evMTT.add(new JLabel(Textes.INFO_evTourney()));
        _evMTT.add(gain);
        panMTT.add(_evMTT);
        JPanel _itmMTT = new JPanel();
        _itmMTT.add(new JLabel(Textes.INFO_itm()));
        _itmMTT.add(itm);
        panMTT.add(_itmMTT);
        JButton gainsMTT = new JButton(Textes.INFO_echelleGains());
        panMTT.add(gainsMTT);
        JPanel _hhhoursMTT = new JPanel();
        _hhhoursMTT.add(new JLabel(Textes.INFO_durationTourney()));
        _hhhoursMTT.add(duree);
        panMTT.add(_hhhoursMTT);
        JPanel _multiRatioMTT = new JPanel();
        _multiRatioMTT.add(new JLabel(Textes.INFO_multiRatio()));
        _multiRatioMTT.add(multiRatio);
        panMTT.add(_multiRatioMTT);
 
        formulaire.add(panMTT, "mtt");
        mtt.addActionListener(this);
            //général formulaires
        panAjout.add(formulaire);
        pan.add(panAjout);
        JButton ok = new JButton("OK");
        ok.addActionListener(new FormulaireListener());
        JPanel okPanel = new JPanel();
        okPanel.add(ok);
        pan.add(okPanel);
 
        //infos actuelles
        JPanel panJeuxActuels = new JPanel();
        panJeuxActuels.setBackground(background);
        JLabel texte = new JLabel("Ici seront les jeux entrés");
        texte.setForeground(foreground);
        panJeuxActuels.add(texte);
            //général jeux actuels
        pan.add(panJeuxActuels);
        /*général*/
        setVisible(true);
    }
 
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == cg) {
            ((CardLayout) formulaire.getLayout()).show(formulaire,"cg");
        }
        else if (e.getSource() == sng)   {
            ((CardLayout) formulaire.getLayout()).show(formulaire,"sng");
        }
        else if (e.getSource() == spin)   {
            ((CardLayout) formulaire.getLayout()).show(formulaire,"spin");
        }
        else {
            ((CardLayout) formulaire.getLayout()).show(formulaire,"mtt");
        }
    }
}
class JLabel extends javax.swing.JLabel {
    public JLabel() {
        super();
        _construct();
    }
    public JLabel(String s) {
        super(s);
        _construct();
    }
    private void _construct() {
        this.setBackground(ClassMain.global().background());
        this.setForeground(ClassMain.global().foreground());
    }
}
class JPanel extends javax.swing.JPanel {
    public JPanel() {
        super();
        _construct();
    }
 
    public JPanel(CardLayout cardLayout) {
        super(cardLayout);
        _construct();
    }
    private void _construct() {
        this.setBackground(ClassMain.global().background());
        this.setForeground(ClassMain.global().foreground());
    }
}
(en passant si vous avez des remarques concernant la qualité [relative] de mon code, je suis preneur :p)

Merci d'avance pour vos réponses