Bonsoir a tous;
j'ai un petite probléme consernant le test du mon textfield telque le probléme est la méthode verification ne fait pas de véification
ca c'est le code du classe ou j'ai déclaré mon textfield
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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
package inerface;
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import com.borland.jbcl.layout.*;
import java.lang.Object;
import java.awt.List;
import javax.swing.text.*;
 
/**
 * <p>Titre : </p>
 * <p>Description : </p>
 * <p>Copyright : Copyright (c) 2008</p>
 * <p>Société : </p>
 * @author non attribuable
 * @version 1.0
 */
 
public class Cadre4 extends JFrame {
  JPanel contentPane;
  JPanel jPanel1 = new JPanel();
  Border border1;
  JPanel jPanel2 = new JPanel();
  Border border2;
  Border border3;
  TitledBorder titledBorder1;
  Border border4;
  Border border5;
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JLabel jLabel6 = new JLabel();
  JLabel jLabel7 = new JLabel();
  JLabel jLabel8 = new JLabel();
  final JTextField jTextField1 = new JTextField();
  JTextField jTextField2 = new JTextField();
  JTextField jTextField3 = new JTextField();
  JTextField jTextField4 = new JTextField();
  JLabel jLabel9 = new JLabel();
  JLabel jLabel10 = new JLabel();
  JLabel jLabel11 = new JLabel();
  JLabel jLabel12 = new JLabel();
  JPanel jPanel3 = new JPanel();
  final JTextField jTextField5 = new JTextField();
  JTextField jTextField6 = new JTextField();
  Border border6;
  JButton jButton1 = new JButton();
  Border border7;
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
GridBagConstraints c = new GridBagConstraints();
  private final static String newline = "\n";
  //final JTextField txt = new JTextField();
  //Construire le cadre
 
  public Cadre4() {
    try {
      jbInit();
 
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public Cadre4(Cadre3 c) {
   this();
  cc=c;
 }
 
Cadre3 cc;
 
  //Initialiser le composant
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
 
    titledBorder1 = new TitledBorder(border3,"Création d'une nouvelle opération ");
    border4 = BorderFactory.createCompoundBorder(new TitledBorder(BorderFactory.createLineBorder(Color.blue,1),"Création d'une nouvelle opération "),BorderFactory.createEmptyBorder(2,2,2,2));
    border5 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.blue,1),BorderFactory.createEmptyBorder(2,2,2,2));
    border6 = BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.blue,1),BorderFactory.createEmptyBorder(2,2,2,2));
    border7 = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,Color.blue,Color.white,new Color(115, 114, 105),new Color(165, 163, 151)),BorderFactory.createEmptyBorder(0,2,2,2));
    contentPane.setLayout(null);
    this.setSize(new Dimension(658, 622));
    this.setTitle("IDENTIFICATION DES ELEMENT DU CLASSE");
    jPanel1.setBackground(Color.white);
    jPanel1.setBorder(BorderFactory.createTitledBorder("Création d'un nouvel attribut"));
    jPanel1.setBorder(border5);
    jPanel1.setBounds(new Rectangle(3, 6, 652, 219));
    jPanel1.setLayout(null);
    jPanel2.setBackground(Color.white);
    jPanel2.setBorder(border2);
    jPanel2.setBorder(border4);
    jPanel2.setBounds(new Rectangle(-1, 229, 657, 194));
    jPanel2.setLayout(null);
    jLabel1.setFont(new java.awt.Font("Dialog", 3, 22));
    jLabel1.setText("Donnez le nom de l\'attribut que vous voulez créer");
    jLabel1.setBounds(new Rectangle(6, 16, 556, 26));
    jLabel2.setBounds(new Rectangle(5, 23, 556, 26));
    jLabel2.setText("Donnez le nom de l\'opération que vous voulez créer");
    jLabel2.setFont(new java.awt.Font("Dialog", 3, 22));
    jLabel3.setFont(new java.awt.Font("SansSerif", 2, 20));
    jLabel3.setText("Nom :");
    jLabel3.setBounds(new Rectangle(3, 55, 71, 23));
    jLabel4.setBounds(new Rectangle(8, 61, 71, 23));
    jLabel4.setText("Nom :");
    jLabel4.setFont(new java.awt.Font("SansSerif", 2, 20));
    jLabel5.setFont(new java.awt.Font("Dialog", 1, 20));
    jLabel5.setText("Vous pouvez donner une description explicite de cet attribut");
    jLabel5.setBounds(new Rectangle(3, 98, 628, 32));
    jLabel6.setBounds(new Rectangle(5, 91, 628, 32));
    jLabel6.setText("Vous pouvez donner une description explicite de cet opération");
    jLabel6.setFont(new java.awt.Font("Dialog", 1, 20));
    jLabel7.setFont(new java.awt.Font("SansSerif", 2, 20));
    jLabel7.setText("Libellé:");
    jLabel7.setBounds(new Rectangle(6, 133, 81, 26));
    jLabel8.setBounds(new Rectangle(6, 126, 81, 26));
    jLabel8.setText("Libellé:");
    jLabel8.setFont(new java.awt.Font("SansSerif", 2, 20));
 
    PlainDocument mydoc = new PlainDocument() {
                           //On redéfinit la méthode insertString
                           public void insertString(int offs, String str, AttributeSet a)
                                     throws BadLocationException
                           {
                                   //On teste si on est à la première position de la zone de saisie
                                   if (offs == 0)
                                   {
                                           //si c'est le cas, on teste si la lettre saisie est en majuscule, ou si on a collé un texte,
                                           //on teste s'il commence par une lettre majuscule, et qu'il ne contient que des caractères, ou des espaces, _
                                           if (str.matches("^[a-z][A-Za-z\\s\\_]*"))
                                                   //si oui, on insère la chaine
                                                   super.insertString(offs, str, a);
                                                 else
                                                    JOptionPane.showMessageDialog(null, "Erreur de saisie:le premier caractére doit écrit en miniscule", "Erreur", JOptionPane.ERROR_MESSAGE);
                                   }
                                   else{
                                     //on teste que la chaine est contient seulement des caractères, ou des espaces
                                     //le \s représente les espaces (espace, tabulations ...)
                                     if (str.matches("[A-Za-z\\s\\_]+"))
                                       //si oui, on insère la chaine
                                       super.insertString(offs, str, a);
                                     else
                                        JOptionPane.showMessageDialog(null, "Erreur de saisie:le premier caractére doit écrit en miniscule", "Erreur", JOptionPane.ERROR_MESSAGE);
                                   }
                           }
                   };
 
    jTextField1.setFont(new java.awt.Font("SansSerif", 2, 20));
    jTextField1.setSelectionColor(SystemColor.inactiveCaptionBorder);
    jTextField1.setText("Entré nom d'attribut");
    jTextField1.selectAll();
    jTextField1.setBounds(new Rectangle(72, 56, 288, 29));
    jTextField1.setDocument(mydoc);
 
    jTextField2.setBounds(new Rectangle(76, 129, 562, 29));
    jTextField2.setText("Entré son libellé");
    jTextField2.setFont(new java.awt.Font("SansSerif", 2, 20));
    jTextField2.setSelectionColor(SystemColor.inactiveCaptionBorder);
    jTextField2.selectAll();
    jTextField3.setBounds(new Rectangle(82, 59, 304, 29));
    jTextField3.setText("Entré le nom d'opération");
    jTextField3.setFont(new java.awt.Font("SansSerif", 2, 20));
    jTextField3.setSelectionColor(SystemColor.inactiveCaptionBorder);
    jTextField3.selectAll();
    jTextField4.setBounds(new Rectangle(83, 126, 559, 29));
    jTextField4.setText("Entré son libellé");
    jTextField4.setFont(new java.awt.Font("SansSerif", 2, 20));
    jTextField4.setSelectionColor(SystemColor.inactiveCaptionBorder);
    jTextField4.selectAll();
    jLabel9.setFont(new java.awt.Font("SansSerif", 2, 20));
    jLabel9.setText("Libellé:");
    jLabel9.setBounds(new Rectangle(6, 126, 81, 26));
    jLabel10.setFont(new java.awt.Font("SansSerif", 2, 20));
    jLabel10.setText("Nom :");
    jLabel10.setBounds(new Rectangle(8, 61, 71, 23));
    jLabel11.setFont(new java.awt.Font("Dialog", 3, 22));
    jLabel11.setText("Donnez le nom du relation que vous voulez créer");
    jLabel11.setBounds(new Rectangle(5, 23, 556, 26));
    jLabel12.setFont(new java.awt.Font("Dialog", 1, 20));
    jLabel12.setText("Vous pouvez donner une description explicite de cet relation");
    jLabel12.setBounds(new Rectangle(5, 91, 628, 32));
    jPanel3.setLayout(null);
    jPanel3.setBounds(new Rectangle(7, 423, 650, 193));
    jPanel3.setBorder(border4);
    jPanel3.setBorder(border6);
    jPanel3.setBackground(Color.white);
 
 
    jTextField5.setBounds(new Rectangle(82, 59, 316, 29));
    jTextField5.setText("Entré le nom du relation d'association");
    jTextField5.setFont(new java.awt.Font("SansSerif", 2, 20));
    jTextField5.setSelectionColor(SystemColor.inactiveCaptionBorder);
    jTextField5.selectAll();
    jTextField5.setInputVerifier(new InputVerifier()
    {
        public boolean verify(JComponent c)
        {
            JTextField txt = (JTextField)c;
            String saisie = txt.getText();
            if (saisie.matches(".*(er|or|ir|or|re)$"))
                return true;
            else
            {
                JOptionPane.showMessageDialog(null, "Le verbe doit être en infinitif",
                        "Erreur", JOptionPane.ERROR_MESSAGE);
                return false;
            }
        }
    });
 
 
    jTextField6.setBounds(new Rectangle(83, 126, 559, 29));
    jTextField6.setText("Entré son libellé");
    jTextField6.setFont(new java.awt.Font("SansSerif", 2, 20));
    jTextField6.setSelectionColor(SystemColor.inactiveCaptionBorder);
    jTextField6.selectAll();
    jButton1.setBackground(Color.white);
    jButton1.setBounds(new Rectangle(484, 180, 110, 29));
    jButton1.setFont(new java.awt.Font("Dialog", 2, 24));
    jButton1.setBorder(border7);
    jButton1.setText("Valider");
    jButton1.addActionListener(new Cadre4_jButton1_actionAdapter(this));
    jButton2.setText("Valider");
    jButton2.addActionListener(new Cadre4_jButton2_actionAdapter(this));
    jButton2.setBorder(border7);
    jButton2.setFont(new java.awt.Font("Dialog", 2, 24));
    jButton2.setBounds(new Rectangle(494, 159, 110, 29));
    jButton2.setBackground(Color.white);
    jButton3.setText("Valider");
    jButton3.addActionListener(new Cadre4_jButton3_actionAdapter(this));
    jButton3.setBorder(border7);
    jButton3.setFont(new java.awt.Font("Dialog", 2, 24));
    jButton3.setBounds(new Rectangle(501, 159, 110, 29));
    jButton3.setBackground(Color.white);
    contentPane.add(jPanel1, null);
    jPanel1.add(jLabel1, null);
    jPanel1.add(jLabel3, null);
    jPanel1.add(jLabel5, null);
    jPanel1.add(jLabel7, null);
    jPanel1.add(jTextField1, null);
    jPanel1.add(jTextField2, null);
    jPanel1.add(jButton1, null);
    contentPane.add(jPanel2, null);
    jPanel2.add(jLabel2, null);
    jPanel2.add(jLabel4, null);
    jPanel2.add(jLabel6, null);
    jPanel2.add(jLabel8, null);
    jPanel2.add(jTextField4, null);
    jPanel2.add(jTextField3, null);
    jPanel2.add(jButton2, null);
    contentPane.add(jPanel3, null);
    jPanel3.add(jLabel11, null);
    jPanel3.add(jLabel10, null);
    jPanel3.add(jLabel12, null);
    jPanel3.add(jLabel9, null);
    jPanel3.add(jTextField6, null);
    jPanel3.add(jTextField5, null);
    jPanel3.add(jButton3, null);
  }
 
 
  void jButton1_actionPerformed(ActionEvent e) {
cc.modellist1.addElement(jTextField1.getText()+newline);
cc.modellist1.addElement(jTextField2.getText()+newline);
 
 }
 
  void jButton2_actionPerformed(ActionEvent e) {
cc.modellist2.addElement(jTextField3.getText()+newline);
cc.modellist2.addElement(jTextField4.getText()+newline);
 
  }
 
  void jButton3_actionPerformed(ActionEvent e) {
cc.modellist3.addElement(jTextField5.getText()+newline);
cc.modellist3.addElement(jTextField6.getText()+newline);
 
  }
 
}
 
class Cadre4_jButton1_actionAdapter implements java.awt.event.ActionListener {
  Cadre4 adaptee;
 
  Cadre4_jButton1_actionAdapter(Cadre4 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}
 
class Cadre4_jButton2_actionAdapter implements java.awt.event.ActionListener {
  Cadre4 adaptee;
 
  Cadre4_jButton2_actionAdapter(Cadre4 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}
 
class Cadre4_jButton3_actionAdapter implements java.awt.event.ActionListener {
  Cadre4 adaptee;
 
  Cadre4_jButton3_actionAdapter(Cadre4 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton3_actionPerformed(e);
  }
}
merci d'avance
salutation