Thursday, 6 March 2014

AWT CONTROLS:TextField

TextField  is subclasses of TextComponent.................

Using a TextField


      A TextField object is a text component that allows for the editing of a single line of text. A scrollable text display object with one row of characters is known as the TextField. 

TextField defines the following constructors:


  •  TextField(): Constructs a new text field.

  •  TextField(int numChars): Constructs a new empty TextField with the specified number of columns.

  •  TextField(String str): Constructs a new text field initialized with the specified text.

  •  TextField(String str, int numChars): Constructs a new text field initialized with the specified text to be displayed, and wide enough to hold the specified number of characters.


TextField defines the following methods:


  • getEchoChar():Gets the character that is to be used for echoing.

                syntax
                    char  getEchoChar()

  •  echoCharIsSet():Indicates whether or not this text field has a character set for echoing.

                syntax
                    boolean echoCharIsSet()


  • setEchoChar(char): Sets the echo character for this text field.

              syntax 
                   void setEchoChar(char)

  • getText() & setText():To obtai the string currently contained in the text field,call getText().To set the text,call setText().

                     syntax
                          String setText()
                           void setText(String str)

  • getSelectedText():It returns the selected text.

             syntax
                    String  getSelectedText()

  • select(int startIndex,int endIndex):The select()method select the characters beginning at startIndex and ending at endIndex.

               syntax:
                     void select(int startIndex,int endIndex)

simple program for handling TextField.


import java.awt.*; 
import java.applet.Applet; 
public class TextFieldDemo extends Applet

public void init()

TextField tf = new TextField("Type in the box"); 
add(tf); 



output






No comments:

Post a Comment