To accept line of textual data from the user AWT provides TextField. It is the subclass of TextComponent. The Constructor for TextField are listed below:
TextField() - It constructs an empty text field.
TextField(String text) - It constructs a text field with the initial content is text.
TextField(int n) - Constructs an empty text field with the n number of columns.
TextField(String text, int n) - Constructs a text field whose initial content is text with n columns.
getText() - It returns the text content of the TextField.
setText() - It set the text for the TextField
setEchoChar(char c) – It allows you to specify an echo character for accepting password. If you have specified “*” as echo character. It displays the “*” in the text field instead of the text the user has keyed in.
Example:
import java.applet.*;
import java.awt.*;
public class TextFieldDemo extends Applet
{
public void init()
{
setLayout(new GridLayout(2, 2));
Label l=new Label("Enter the user Name",Label.CENTER);
TextField t1=new TextField();
Label l1=new Label("Enter your Password",Label.CENTER);
TextField t2=new TextField(10);
t2.setEchoChar('*');
add(l);
add(t1);
add(l1);
add(t2);
}
}
/*
* <applet code="TextFieldDemo.class" width=250 height=50>
* </applet>
*/
How to Execute this Example??
d:\> javac TextFieldDemo.java
d:\> appletviewer TextFieldDemo.java
Output:
0 comments :
Post a Comment