Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Create TextBox in java (http://www.go4expert.com/forums/create-textbox-java-t21771/)

satyedra pal 15Apr2010 12:19

Create TextBox in java
 
TextBox is used in two ways TextField and TextArea.The TextField and TextArea are two different classes in Java for input text data and also displaying text data.The TextField class manage only one line of string or text and TextArea class manages multiple lines or multiple string.
We are giving the example of TextField class example.In this example we are giving the size of the textField within bracket.

TextField txt = new TextField(25);
If we want to show the text for the TextField then we write following code:


TextField txt = new TextField("your full name");
For entering text in TextField we use "setText()" method.And for finding the input from the textField we use "getText()"method.
For example: For entering txt.setText("Bye"); for reteriving txt.getText();

Now we are giving an example of a class for TextBox implementation.


import java.applet.*;
import java.awt.*;

public class txtdemo extends Applet

{
TextField txt1 = new TextField(25);
TextField passtxt1 = new TextField(10);
TextField txt2 = new TextField(25);
TextField passtxt2 = new TextField(10);
Button button1=new Button("after entering press");


public void init()
{
add(txt1)
add(txt2);
passtxt1.setEchoCharacter('*');
add(passtxt1);
passtxt2.setEchoCharacter('*');
add(passtxt2);
add(button1);
}

public boolean action(Event evt,Object obj)
{
if (evt.target ==txt1)
{
txt2.setText(txt1.getText());
return true;
}
if (evt.target == passtxt1)
{
passtxt2.setText(passtxt1.getText());
return true;
}

}
}

In TextArea we can not use Action method.


All times are GMT +5.5. The time now is 06:41.