bonsoir


j'ai un problème je veux faire un test sur le JFormattedTextField si je click sur le bouton alors vérifié si les chiffres saisis inférieurs à 3 alors déclenche message

voila le 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
 
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
 
import javax.swing.JFormattedTextField;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.text.MaskFormatter;
 
import java.awt.Rectangle;
 
public class allo extends JFrame {
private JFormattedTextField jtf = null;  
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JButton jButton = null;
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(39, 50, 75, 55));
			jButton.setText("Entrer");
		}
		return jButton;
	}
 
private JFormattedTextField  getJTextField2() {
if (jtf == null) {
MaskFormatter mask = new MaskFormatter();
jtf = new JFormattedTextField(mask);
 
 
 try {
 
	mask.setMask("###");
  mask.setValidCharacters("1234567890");
    } catch (Exception e) {
     e.printStackTrace();
   }
				    mask.setAllowsInvalid(false);				    jtf.setFocusLostBehavior(JFormattedTextField.PERSIST);
  jtf.setBounds(new Rectangle(134, 51, 145, 51));
}
return jtf;
} 
public static void main(String[] args) {
TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
allo thisClass = new allo();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public allo() {
super();
initialize();
}
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}
 
 
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJTextField2(), null);
		}
		return jContentPane;
	}
 
}