Home Segments Top Top Previous Next

913: Mainline

The constructor for instances of the JTextField class specifies an initial string and the number of columns associated with the text field. For example, the following statement creates a 20-column text field, initialized to display a one character string, "0", and assigned to a JTextField variable, field1:

field1 = new JTextField("0", 20); 

Then, when the following add statement appears inside the constructor for a panel, the initial string, "0", is displayed in a text field at a place dictated by the panel's layout manager:

add(field1);