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()

public boolean action(Event evt,Object obj)
if (evt.target ==txt1)
return true;
if (evt.target == passtxt1)
return true;


In TextArea we can not use Action method.

All times are GMT +5.5. The time now is 07:24.