Bonjour,

j'ai un problème qui parait simple mais je ne comprends pas pourquoi ceci ne fonctionne pas. en fait j'ai un JPasswordField qui je veux fixer la taille maximale qui 8.
j'ai cherché sur le net j'ai trouvé cette instruction
Code : Sélectionner tout - Visualiser dans une fenêtre à part
text2= new JPasswordField(8);
mais quand j'applique ça dans mon code ceci n'est pas pris en considération:
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
package Distributeur;
 
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
 
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;
 
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
 
 
 
 
public class authentification implements ActionListener {
	private JFrame f;
	private JPanel p;
	private JButton b1;
	private JButton b2,b3;
	private JLabel lab1;
	private JLabel lab2;
	private JLabel lab3;
	private JRadioButton rd1;
    private JRadioButton rd2;
    private JTextField text1;
    private JPasswordField text2;
    public authentification(){
    	f=new JFrame();
    	f.setTitle("Connexion");
    	f.setVisible(true);
 
	    f.setSize(580, 380);
 
	    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
	    f.setLocationRelativeTo(null);
	    p=new JPanel(new GridBagLayout());
	    p.setBackground(Color.cyan);
	    Font policeL = new Font("Times New Roman", Font.BOLD, 16);
	    Font policeC= new Font("Arial", Font.BOLD, 18);
	    Border thickBorder = new LineBorder(Color.black, 3);
 
	    GridBagConstraints c=new GridBagConstraints();
	    b1=new JButton("Connexion");
	    b2=new JButton("Inscription");
	    b3=new JButton("Exit");
	    lab1=new JLabel("Type of User");
	    lab2=new JLabel("Login");
	    lab3=new JLabel("Passe Word");
	    rd1=new JRadioButton("Customer");
	    rd2=new JRadioButton("Manager");
	    text1=new JTextField();
	    text2= new JPasswordField(8);
	    b1.setFont(policeC);
	    b2.setFont(policeC);
	    b3.setFont(policeC);
	    lab1.setFont(policeL);
	    lab2.setFont(policeL);
	    lab3.setFont(policeL);
	    lab1.setForeground(Color.BLUE);
	    lab2.setForeground(Color.BLUE);
	    lab3.setForeground(Color.BLUE);
	    rd1.setFont(policeL);
	    rd2.setFont(policeL);
	    rd1.setBackground(Color.cyan);
	    rd2.setBackground(Color.cyan);
	    ButtonGroup group = new ButtonGroup();
	    group.add(rd1);
	    group.add(rd2);
	    b1.addActionListener(this);
	    b2.addActionListener(this);
	    b3.addActionListener(this);
	    c.gridx=0;
	    c.gridy=0;
	    c.insets=new Insets(0,40,0,0);
	    p.add(lab1,c);
	    c.insets=new Insets(0,0,0,0);
	    c.gridx=1;
	    c.gridy=1;
	    p.add(rd1,c);
	    p.add(rd2);
	    c.gridx=0;
	    c.gridy=2;
	    c.insets=new Insets(40,40,40,40);
	    p.add(lab2,c);
	    c.insets=new Insets(0,0,0,0);
	    c.gridx=1;
	    c.gridy=2;
	    c.weightx = 4.0;
        c.fill = GridBagConstraints.HORIZONTAL;
	    p.add(text1,c);
	    c.weightx = 4.0;
        c.fill = GridBagConstraints.HORIZONTAL;
	    c.gridx=0;
	  c.gridy=4;
	   text1.setPreferredSize(new Dimension(100, 30));
	   c.insets=new Insets(0,80,0,0);
	    p.add(lab3,c);
	    c.insets=new Insets(0,0,0,0);
	    c.gridx=1;
	    c.gridy=4;
	    p.add(text2,c);
	    c.gridx=0;
	    c.gridy=5;
	    text2.setPreferredSize(new Dimension(150, 30));
	    p.add(b1,c);
	    c.gridx=1;
	    c.gridy=5;
	    c.insets=new Insets(40,40,40,40);
	    p.add(b2,c);
	    c.gridx=2;
	    c.gridy=5;
	    c.insets=new Insets(0,0,0,0);
	    p.add(b3,c);
	    b1.setBorder(thickBorder);
	    b1.setPreferredSize(new Dimension(100, 50));
	    b2.setBorder(thickBorder);
 
	    b2.setPreferredSize(new Dimension(100, 50));
	    b3.setBorder(thickBorder);
	    b3.setPreferredSize(new Dimension(100, 50));
 
 
	    f.add(p,BorderLayout.CENTER);
 
 
 
 
	    }
 
 
    public static void main(String []args){
		 new creation();
 
	 }
 
 
 
 
 
 
 
 
 
	@Override
	public void actionPerformed(ActionEvent arg0) {
		String log,mot;
		Connection laConnection;
		 if (rd1.isSelected()){
			 log=text1.getText();
		    	mot=new String(text2.getPassword());
		    	System.out.println(log);
		    	System.out.println(mot);
 
 
				try
				{ 
				Class.forName("com.mysql.jdbc.Driver");
 
				laConnection =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost/application?useSSL=false","boutheina","30071986"); 
 
				String sql = "select login,psw from client where login =? and psw=?"; 
 
				try( PreparedStatement preparedStatement = (PreparedStatement) laConnection.prepareStatement(sql) ) { //préparation de la requête 
 
				    preparedStatement.setString(1,log);  //on assigne le login au premier paramètre 
 
				    preparedStatement.setString(2,mot);  //on assigne le mot de passe au second paramètre 
 
				    ResultSet result = preparedStatement.executeQuery(); // exécution de la requête
				    if ( result.next() ) { // s'il y a un résultat, alors le couple login/password existe
				        // connexion réussie
				    	System.out.println("Vous avez le droit d'entrer");
				    	new client();
				    }
				    else {
				        // connexion échouée
				    	System.out.println("Vous n'avez pas le droit d'entrer");
				    	JOptionPane.showMessageDialog(null, "Your Login and/or your Passeword are Incorrects", 
                                "Error Message",
                                JOptionPane.ERROR_MESSAGE);
				    	text1.setText("");
				    	text2.setText("");
				    	text1.getCursor();
				    }
 
				}
 
				}
 
				catch
				(Exception e)
				{
				            System.out.print("impossible de se connecter à la base");
 
				}   
 
 
		 }
 
 
		 if (rd2.isSelected()){
			 log=text1.getText();
		    	mot=new String(text2.getPassword());
		    	System.out.println(log);
		    	System.out.println(mot);
 
 
				try
				{ 
				Class.forName("com.mysql.jdbc.Driver");
 
				laConnection =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost/application?useSSL=false","boutheina","30071986"); 
 
				String sql = "select login,passeword from manager where login =? and passeword=?"; 
 
				try( PreparedStatement preparedStatement = (PreparedStatement) laConnection.prepareStatement(sql) ) { //préparation de la requête 
 
				    preparedStatement.setString(1,log);  //on assigne le login au premier paramètre 
 
				    preparedStatement.setString(2,mot);  //on assigne le mot de passe au second paramètre 
 
				    ResultSet result = preparedStatement.executeQuery(); // exécution de la requête
				    if ( result.next() ) { // s'il y a un résultat, alors le couple login/password existe
				        // connexion réussie
				    	System.out.println("Vous avez le droit d'entrer");
				    	new manager();
				    }
				    else {
				        // connexion échouée
				    	System.out.println("Vous n'avez pas le droit d'entrer");
				    	JOptionPane.showMessageDialog(null, "Your Login and/or your Passeword are Incorrects", 
                                "Error Message",
                                JOptionPane.ERROR_MESSAGE);
				    	text1.setText("");
				    	text2.setText("");
				    	text1.getCursor();
				    }
 
				}
 
				}
 
				catch
				(Exception e)
				{
				            System.out.print("impossible de se connecter à la base");
 
				} 
		 }
 
	}
}
est ce que quelqu'un peut m'aider