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

Answer:

The Java documentation from Oracle© is the best place.

At the moment, the documentation is here: http://www.oracle.com/technetwork/java/javase/documentation/index.html but this might change.


Application with a JTextField

GUI of the application

Look through the official documentation to see what is in it. The purpose of these notes is to overview the Swing package. Look to the documentation for complete coverage.

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

JTextField( int numChars ) 

The parameter is number of characters, not the size in pixels. The following program displays the frame at the top of this page.

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

public class TextEg1 extends 
{

   text;

  // constructor for TextEg1
  public TextEg1( String title )
  { 
    super( title ); 
    
    text = new  ;
    
    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 4:

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