je veux que le champs numT n'accepte des numéro
je veut faire ça dans une exception mais je ne peut pas vérifier si jtextfield de numT reçoit que des numéro
merci
voici mon code:
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
 
package mini_projet;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
 
 
 
 
 
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
class NoteException extends Exception{
 
 
	public NoteException() {
		JOptionPane.showMessageDialog(null, "note invalid une note doit etre cmprise entre 0 et 20","error",JOptionPane.WARNING_MESSAGE);
 
 
	}}
class IsEmptyException extends Exception{
	public IsEmptyException() {
		// TODO Auto-generated constructor stub
		JOptionPane.showMessageDialog(null, "veuillez remplir tout les champs","error",JOptionPane.WARNING_MESSAGE);
 
	}}
 
 
 
public class Info_Etud extends JPanel implements ActionListener,KeyListener ,ItemListener{
	static ArrayList<Etudiant> listg1=new ArrayList<Etudiant>();
	static ArrayList<Etudiant> listeg2=new ArrayList<Etudiant>();
	static ArrayList<Etudiant> listeg3=new ArrayList<Etudiant>();
	JButton quitter= new JButton("Quitter");
	JButton enregistrer= new JButton("Enregistrer");
	JLabel nom=new JLabel("Nom :");
	JTextField txtNom=new JTextField(20);
 
	JLabel prenom=new JLabel("Prénom :");
	JTextField txtPre=new JTextField(20);
 
	JLabel numT=new JLabel("Num Tel :");
	JTextField txtNumT=new JTextField(20);
 
	JLabel grp=new JLabel("Groupe:");
	JComboBox<String> comboGrp=new JComboBox<String>();
 
	JLabel noteC=new JLabel("Note du Controle :");
	JTextField txtNoteC=new JTextField("0",7);
 
	JLabel noteP=new JLabel("Note du projet :");
	JTextField txtNoteP=new JTextField("0",7);
 
	JLabel moy=new JLabel("moyenne :");
	JTextField txtMoy=new JTextField(7);
 
	JButton changerCoe=new JButton("changer coefficient");
	JCheckBox consulterG1=new JCheckBox("consulter groupe 1");
	JCheckBox consulterG2=new JCheckBox("consulter groupe 2");
	JCheckBox consulterG3=new JCheckBox("consulter groupe 2");
 
 
	public Info_Etud () {
 
		comboGrp.addItem("groupe1");
		comboGrp.addItem("groupe2");
		comboGrp.addItem("groupe3");
		quitter.setBorderPainted(true);
		quitter.setBackground(Color.WHITE);
		quitter.setForeground(Color.black);
 
		enregistrer.setBorderPainted(true);
		enregistrer.setBackground(Color.WHITE);
		enregistrer.setForeground(Color.black);
 
		JPanel pinfo=new JPanel();
		JPanel p1=new JPanel();
 
		p1.setBackground(Color.white);
		p1.add(nom); 
		p1.add(txtNom);
		JPanel p2=new JPanel();
		p2.setBackground(Color.white);
		p2.add(prenom); 
		p2.add(txtPre);
		JPanel p3=new JPanel();
		p3.setBackground(Color.white);
		p3.add(numT);
		p3.add(txtNumT);
		JPanel p4=new JPanel();
		p4.setBackground(Color.white);
		p4.add(grp);
		p4.add(comboGrp);
 
 
		JPanel pbutton=new JPanel();
		pbutton.setBackground(Color.white);
		pbutton.add(enregistrer); pbutton.add(quitter);
		pbutton.add(consulterG1);pbutton.add(consulterG2);
		pbutton.add(consulterG3);
 
 
		pinfo.setLayout(new BoxLayout(pinfo, BoxLayout.Y_AXIS));
		pinfo.add(p1);
		pinfo.add(p2);
		pinfo.add(p3);
		pinfo.add(p4);
 
		JPanel pnote =new JPanel();
		pnote.setLayout(new BoxLayout(pnote, BoxLayout.Y_AXIS));
		JPanel p5 =new JPanel();
		JPanel p6 =new JPanel();
		JPanel p7 =new JPanel();
		JPanel p8=new JPanel();
		p5.setBackground(Color.white);
		p5.add(noteC);
		p5.add(txtNoteC);
		p6.setBackground(Color.white);
		p6.add(noteP);
		p6.add(txtNoteP);
		p7.setBackground(Color.white);
		p7.add(moy);
		p7.add(txtMoy);
 
		p8.setBackground(Color.white);
		p8.add(changerCoe);
 
		pnote.add(p5);
		pnote.add(p6);
		pnote.add(p7);
		pnote.add(p8);
 
 
		this.setLayout(new BorderLayout());
		this.add(pinfo,BorderLayout.CENTER);
		this.add(pnote, BorderLayout.EAST);
		this.add(pbutton, BorderLayout.SOUTH);
 
		setVisible(true);
 
		enregistrer.addActionListener(this);
		//quitter.addMouseListener
		consulterG1.addItemListener(this);
		consulterG2.addItemListener(this);
		consulterG3.addItemListener(this);
 
		txtNoteC.addKeyListener(this);
 
 
		txtNoteP.addKeyListener(this);
 
	}
 
	public static void main(String[] args) {
		new Info_Etud();
	}
 
	@Override
	public void actionPerformed(ActionEvent e) {
		Object s= e.getSource();
		JButton b= (JButton)s;
 
 
 
 
 
		if (b==enregistrer){
			try {
				String g=(String)comboGrp.getSelectedItem();
				float c=Float.parseFloat(txtNoteC.getText()) ;
				float p=Float.parseFloat(txtNoteP.getText()) ;
				float m=Float.parseFloat(txtMoy.getText()) ;
				if ((c<0 || c>20) || (p<0 || p>20) )throw new NoteException();
				if((txtNom.getText().isEmpty())||(txtPre.getText().isEmpty())||(txtNumT.getText().isEmpty())||(g.isEmpty())||((txtNom.getText().isEmpty())&&(txtPre.getText().isEmpty())&&(txtNumT.getText().isEmpty())&&(g.isEmpty())))throw new IsEmptyException();
 
				Etudiant A= new Etudiant(txtNom.getText(),txtPre.getText(),txtNumT.getText(),g,c,p,m);
				if(comboGrp.getSelectedItem().equals("groupe1"))
 
					listg1.add(A);
				else
					if(comboGrp.getSelectedItem().equals("groupe2"))
						listeg2.add(A);
					else
						listeg3.add(A);
				JOptionPane.showMessageDialog(null, "etudiant enregistre !! ");
				txtNom.setText("");
				txtPre.setText("");
				txtNumT.setText("");
				txtNoteC.setText("");
				txtNoteP.setText("");
				txtMoy.setText("");
 
 
 
			}
			catch (NoteException e1) {
				// TODO: handle exception
 
			}
			catch(IsEmptyException e2 ) {
 
			}
			catch(NumberFormatException e3) {
				JOptionPane.showMessageDialog(null, "remplir le champs moyenne","error",JOptionPane.WARNING_MESSAGE);
 
			}
			}
	}
 
	@Override
	public void keyPressed(KeyEvent arg0) {
		// TODO Auto-generated method stub
 
	}
 
	@Override
	public void keyReleased(KeyEvent arg0) {
		// TODO Auto-generated method stub
		Float op=((Float.parseFloat(txtNoteC.getText())*2)+Float.parseFloat(txtNoteP.getText()))/3;
		txtMoy.setText(op+" ");
	}
 
	@Override
	public void keyTyped(KeyEvent arg0) {
		// TODO Auto-generated method stub
 
	}
 
	@Override
	public void itemStateChanged(ItemEvent arg0) {
		// TODO Auto-generated method stub
 
		if (consulterG1.isSelected()){
			new ListeE1();
			consulterG1.setSelected(false);
		}
		else
			if (consulterG2.isSelected()){
 
				new ListeE2();
 
				consulterG2.setSelected(false);
			}else {
				if(consulterG3.isSelected())
					new ListeE3();
				consulterG3.setSelected(false);
 
			}}
 
 
}