Articles : JavaBoutique's Introduction to Java :
Components :

Contents
Introduction
Static Text with Label
Text Entry Components
Check Boxes and Check Box Groups
Choices
Lists
Menus and Menu Bars
Scrollbars, Buttons, and Canvases

Text Entry Components

The JDK also provides the TextField and TextArea components which allow you to get user input. They are derived from TextComponent, so if you are looking for a method that should obviously be there, you should check TextComponent right away.

import java.awt.*;

public class TextEntryExample
  {
  public static void main(String[] args)
    {
    Frame baseFrame = new Frame();
    baseFrame.setLayout(new GridLayout(2,1));
    baseFrame.reshape(10,10,200,200);
    baseFrame.setTitle("Label Example");

    TextField myTextField = new TextField();
    myTextField.setText("Here is some " +
             "default and selected text");
    myTextField.setSelectionStart(0);
    myTextField.setSelectionEnd(4);
    myTextField.setEditable(false);

    TextArea myTextArea = new TextArea
        ("The Text Area widget \n" +
         "allows multiple line text entry." +
         "it is also worth \n noting that it " +
         "will dynamically create scroll " +
         "bars \n if the text goes beyond the " +
         "boundaries of the widget");

    baseFrame.add(myTextField);
    baseFrame.add(myTextArea);

    baseFrame.show();
    }
  }

When compiled and executed, the code above produces the following interface:

NEXT


Selena Sol contributes to the JavaBoutique's Introduction to Java. Selena currently works for Barclays Capital in London, one of the leading global investment banks in Europe and has worked as a software developer for the National Center for Human Genome research, Microline Software, Neuron Data, and Electric Eye in Singapore. Selena is perhaps best-known for creating the Public Domain Web Script Archive (Extropia) and writing several books on Web Programming (Perl, CGI, Java).
Email: selena@extropia.com