go to previous page   go to home page   go to next page

Answer:

See below.


Runnable Program

The field is 15 characters long, which means that 15 characters will be displayed. The text field can hold more than 15 characters. 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( String title )
  {  
     super( title );
     text = new JTextField( 15 );
     setLayout( new FlowLayout() );
     add( text );
     setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
  }

  public static void main ( String[] args )
  {
    TextEg1 teg  = new TextEg1( "JTextField" ) ;
    teg.setSize( 300, 100 );     
    teg.setVisible( true );      
  }

QUESTION 5:

It would be nice if the frame had some words next to the text field that described its purpose. What is the Swing class for labels?