A
Text field is a linear area that allows users to enter and edit text. The text field inherits from the text component let's Select the text, let's get the text that we choose as a string, get or set the text, and set the text field to be editable as well as the related methods we found in the online reference book. The following example will prove the other features of the text field; We can note that the method name is obvious:
//: Textfield1.java//Using The Text field control import java.awt.*; import java.applet.*;
public class TextField1 extends Applet {button B1 = New button ("Get Text"), B2 = New button ("Set Text");
TextField t = new TextField ("Starting text", 30);
string s = new string ();
public void Init () {Add (B1);
Add (B2);
Add (t); Public boolean action (Event evt, Object Arg) {if (Evt.target.equals (B1)) {getAppletContext (). Showstatus (T.
GetText ());
s = T.getselectedtext ();
if (s.length () = = 0) s = t.gettext ();
T.seteditable (TRUE);
else if (evt.target.equals (B2)) {T.settext ("Inserted by Button 2:" + s);
T.seteditable (FALSE);
}//Let's base class handle It:else return Super.action (EVT, ARG); return true; We ' ve handled it here}}///:~
There are several ways to build a text field, one of which is to provide an initial string and to set the size of the character value field.
Press button 1 To get the text we choose with the mouse is to get all the text in the field and convert it to the string s. It also allows fields to be edited. Press button 2 to place a message and string s to text fields, and prevent the field from being edited (although we can always select text). The editable character of the text is controlled by the true and false value of the seteditable ().