Java Code:
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 | import javax.swing.*; import java.awt.event.*; import java.awt.*; public class JavaSwingJPasswordField extends JFrame { public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setTitle("JPasswordField Test"); frame.setLayout(new GridLayout(2, 2)); JLabel label = new JLabel("User Name:", SwingConstants.RIGHT); JLabel label2 = new JLabel("Password:", SwingConstants.RIGHT); JTextField userNameField = new JTextField(20); JPasswordField passwordField = new JPasswordField(); frame.add(label); frame.add(userNameField); frame.add(label2); frame.add(passwordField); frame.setSize(200, 70); frame.setVisible(true); } } |
Output:
