Text fields in Java

Source: Internet
Author: User
Tags gettext

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.