JTextField Login Validation Example Java Swing

JTextField Login Validation Example Java Swing


In the following program, user name and password are taken from user using JTextField and JPasswordField.

JTextField

JTextField is equivalent to TextField of AWT. JPasswordField does not exist in AWT and is overcome with setEchoChar() method of TextField. JPasswordField is equivalent to HTML <input type=password>.

tf2.setEditable(false);

The JTextField tf2 is meant for the programmer to display the result of validation and not to the user to enter any text. To make the code user-friendly, the tf2 is made non-editable so that it is read-only.

String str1 = tf1.getText();
tf2.setText(“VALID”);

getText() and setText() are the methods of JTextField used to retrieve the text entered by the user and to display some text to the user.

One thought on “JTextField Login Validation Example Java Swing

Leave a Reply

Your email address will not be published. Required fields are marked *