A good answer might be:

The Java documentation from Sun Microsystems is the best place.

Application with a Text Field

You may have this documentation on your computer already, perhaps at C:\jdk1.3.1_01\docs\index.html or a similar location. Go to:


Look around a bit to see how these notes relate to the official documentation. The purpose of these notes is to overview the Swing package. Look to the documentation for complete coverage.

If you can't find the Java documentation on your system you might not have downloaded it from Sun. It would be well worth your time to do this.

Here is one (of several) constructors for JTextField. The parameter says how many characters wide the field is.

JTextField( int numChars ) 

This program displays the frame at right.

import java.awt.*; 
import java.awt.event.*;
import javax.swing.*;

public class TextEg1 extends _______

  _________ text;

  // constructor for TextEg1
  public TextEg1()
    text = new _______________;
    getContentPane().setLayout( new FlowLayout() );
    getContentPane().add( text )

  public static void main ( String[] args )
    . . . . .

  . . . . .


Fill in the blanks so that the field is 15 characters wide.