Advertisement
RupeshAcharya60

JPasswordField with ActionListner

Mar 24th, 2023 (edited)
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5.  
  6. class PasswordField implements ActionListener{
  7.     JFrame frame;
  8.     JPasswordField pass;
  9.     JButton b1;
  10.     JTextField t1;
  11.     JLabel l1;
  12.     PasswordField(){
  13.         frame = new JFrame();
  14.         frame.setLayout(new GridLayout(2,3));
  15.         pass = new JPasswordField();
  16.         t1 = new JTextField(1);
  17.         l1 = new JLabel("Typed Password:");
  18.         b1 = new JButton("Change Bullet:");
  19.  
  20.         b1.addActionListener(this);
  21.         pass.addActionListener(this);
  22.  
  23.         //changing the echo character that is displayed while entering password in JPasswordField
  24.  
  25.  
  26.  
  27.  
  28.         frame.add(pass);
  29.         frame.add(t1);
  30.         frame.add(b1);
  31.         frame.add(l1);
  32.         frame.setSize(400,400);
  33.         frame.setVisible(true);
  34.  
  35.     }
  36.     public void actionPerformed(ActionEvent event){
  37.                   char a = t1.getText().charAt(0);
  38.                   System.out.println(event.getSource());
  39.                   pass.setEchoChar(a);
  40.                   l1.setText("Typed Password:"+pass.getPassword());
  41.  
  42.     }
  43.  
  44. }
  45.  
  46. public class GUI{
  47.  
  48.         public static void main(String[] args){
  49.  
  50.             new PasswordField();
  51.  
  52.         }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement