Bonjour,
J'aimerai que lorsque je saisi un text au clavier l'ecran affiche des '*'
comme pour cacher un mot de passe...
Peut on m'aider????
Merci et bon app...
Bonjour,
J'aimerai que lorsque je saisi un text au clavier l'ecran affiche des '*'
comme pour cacher un mot de passe...
Peut on m'aider????
Merci et bon app...
oui,
javax.swing.JPasswordField
bon courage
Providing a Password Field
Here's the code from PasswordDemo that creates and sets up the password field.
As with text fields, the argument passed into the JPasswordField constructor indicates that the field should be 10 columns wide. By default a password field displays an asterisk '*' for each character typed. The call to setEchoChar changes it to a pound sign '#'. Finally, the code adds an action listener to the password field, which action-validates the value typed in by the user. Here's the implementation of the action listener's actionPerformed method:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 JPasswordField passwordField = new JPasswordField(10); passwordField.setEchoChar('#'); passwordField.addActionListener(new ActionListener() { ... });
The getPassword returns a character array. Password information should not be stored or passed around in strings because strings are not secure.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 public void actionPerformed(ActionEvent e) { JPasswordField input = (JPasswordField)e.getSource(); char[] password = input.getPassword(); if (isPasswordCorrect(password)) { JOptionPane.showMessageDialog(f, "Success! You typed the right password."); } else { JOptionPane.showMessageDialog(f, "Invalid password. Try again.", "Error Message", JOptionPane.ERROR_MESSAGE); } }
A program using a password field typically validates the password before completing any actions requiring the password. This program calls a private method, isPasswordCorrect, that compares the value returned by getPassword to a value stored in a character array.
ET VOILA
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager