JPasswordField

Résolu/Fermé
eniso Messages postés 19 Date d'inscription vendredi 29 mars 2013 Statut Membre Dernière intervention 10 mars 2014 - 1 mai 2013 à 14:28
eniso Messages postés 19 Date d'inscription vendredi 29 mars 2013 Statut Membre Dernière intervention 10 mars 2014 - 1 mai 2013 à 16:31
Bonjour,



j'essaye d'afficher les caractéres que j'ai tapé d'un passwordfield mais je n'y arrive pas j'ai utilisé un jpasswordField et un jRadioButton pourque je puisse afficher les caractéres de mon password dés que j'appuie sur ce jradiobutton.. aidez moi svp :)

2 réponses

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
1 mai 2013 à 14:47
Et où est le problème ? Il nous faut ton code pour t'aider à le corriger !

PS. Pourquoi un JRadioButton ? Un JCheckBox est plus adapté ici...

Exemple :

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPasswordField;

public class Test
{
    public static void main(String[] args)
    {
        final JPasswordField pwd = new JPasswordField();
        
        final JCheckBox check = new JCheckBox("Afficher");
        check.addActionListener(new ActionListener()
        {
            private final char defaultChar = pwd.getEchoChar();
            
            @Override
            public void actionPerformed(ActionEvent e) 
            {
                if (check.isSelected())
                    pwd.setEchoChar('\0');
                else
                    pwd.setEchoChar(defaultChar);
            }
        });
        
        final JFrame frame = new JFrame();
        frame.setLayout(new GridLayout(2,1));
        frame.setLocationRelativeTo(null);
        frame.add(pwd);
        frame.add(check);
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        
    }
}
0
eniso Messages postés 19 Date d'inscription vendredi 29 mars 2013 Statut Membre Dernière intervention 10 mars 2014
1 mai 2013 à 16:31
merci beaucoup :)) votre reponse est efficace . le probleme est resolu :)
0