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
|
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
public class UtilisationTouche extends JFrame {
private static final long serialVersionUID = 1L;
private JPasswordField txtpassword = new JPasswordField(15);
private JButton cmdOK = new JButton("OK");
private JButton cmdCancel = new JButton("Annuler");
public UtilisationTouche() {
super(" Rentrer votre mot de passe");
this.setResizable(false);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
initControles();
this.pack();
}
private void initControles() {
JPanel zc = (JPanel) this.getContentPane();
zc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
zc.add(new JLabel("Mot de passe "), BorderLayout.WEST);
zc.add(txtpassword, BorderLayout.CENTER);
JPanel panButton = new JPanel(new GridLayout(1, 2, 5, 5));
panButton.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
panButton.add(cmdOK);
panButton.add(cmdCancel);
zc.add(panButton, BorderLayout.SOUTH);
// Abonnements
txtpassword.addKeyListener(new TextKeyListener());
}
class TextKeyListener extends KeyAdapter {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
txtpassword_click();
}
}
}
public void txtpassword_click() {
// Ouvre une fenêtre
JOptionPane.showMessageDialog(this, " Test", " A Propos...", JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String[] args) {
new UtilisationTouche().setVisible(true);
}
} |
Partager