See below.
The field is 15 characters long, which means that 15 characters will be displayed. The object can hold more than 15, but the user will have to use the arrow keys on the keyboard to scroll through them.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TextEg1 extends JFrame { JTextField text; public TextEg1() { text = new JTextField( 15 ); getContentPane().setLayout( new FlowLayout() ); getContentPane().add( text ) } public static void main ( String[] args ) { TextEg1 teg = new TextEg1() ; WindowQuitter wquit = new WindowQuitter(); teg.addWindowListener( wquit ); teg.setSize ( 300, 100 ); teg.setVisible( true ); } } class WindowQuitter extends WindowAdapter { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } }
This program can be copied to NotePad, saved to a file, compiled, and run.