Three text fields, nameField, passField, resultField and three labels, lab1, lab2, lab3 are created.
passField.addActionListener(this);
The text field passField is registered with ActionListener using addActionListener() method of TextField. Pressing Enter key in passField generates an event but pressing Enter key in nameField and resultField do not have any event handling as they are not registered with ActionListener (as not required in the program).
passField.setEchoChar(‘*’);
resultField.setEditable(false);
passField is meant for entering password. Password should be secret and for this reason passField characters entered by the user are echoed (displayed) as *. resultField is not allowed by the user to enter any text as it is meant for the programmer to display the result.
String str1 = nameField.getText();
resultField.setText(“VALID”);
Two methods exist in TextField used very often – getText() and setText(). getText() returns the text entered by the user in the text field and setText() method places the text in the text field.
Another program on text field is given Java TextField – Setting Properties where properties for the text field are given with different methods of TextField. For practice, a text field with applet is given in TextField Applet – Adding Two Numbers. The frame you get do not close when clicked over the close icon on the title bar of the frame. It requires extra code close icon to work.
Thanks for sharing.
How to open welcome message in new Jframe after validation of credentials?
how to set a limit of a textfield ,like it cannot contain less than 6 characters.?
I have, how we give validation for textbox in java code(java jdk1.7)
JDK 1.7 does not provide any extra validation code. It must be done by you only as given in my example.
I have a question , if I enter any value in textfied then I want another value will be come in another textfield based on previous text field. using awt frame in java
and another question is how to add print facility on a button click .
i have done printing work but it give low quality print ..
Similar program is there in way2java where when two numbers are entered in two text fields, the result comes in third text field.
Regarding print facility, contact your friends in the office.