Home / ພື້ນຖານ Desktop app / GUI_Component / JPasswordField
ສຳລັບ Password Field ຫຼື JPasswordField (javax.swing.JPasswordField) ຈັດຢູ່ໃນກຸ່ມຂອງ Component ໃຊ້ສຳລັບເປັນ Input ຂໍ້ມູນໃນຮູບແບບຂອງ Password (ລະຫັດຜ່ານ) ທີ່ເປັນເຄື່ອງໝາຍລະຫັດ ແທນການສະແດງລະຫັດຜ່ານແທ້
public class MyForm extends JFrame {
public MyForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 362, 249);
setTitle("Kittisay Java");
setLayout(null);
// Password Field
JPasswordField password = new JPasswordField();
password.setBounds(108, 26, 139, 20);
add(password);
// Label
JLabel lbl = new JLabel("Result");
lbl.setBounds(103, 120, 144, 14);
add(lbl);
// Button
JButton btn1 = new JButton("Button 1");
btn1.addActionListener((e) -> {
String passText = new String(password.getPassword());
lbl.setText("Password = " + passText);
});
btn1.setBounds(128, 72, 99, 23);
add(btn1);
}
public static void main(String[] args) {
MyForm frm = new MyForm();
frm.setVisible(true);
}