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

Answer:

See below.

Raster Order

GUI of the program

Above the frame for the program. Observe how the components have been laid out.

FlowLayout is like a firehose that squirts out the components onto the frame in the same order in which they are added by the program. It starts in the top left, goes across the frame until it hits the right edge, then starts another left to right sweep far enough down to avoid the first row of components (this is called "raster order".) It also centers components within their row.

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

public class TextEg2 extends JFrame
{
  JTextField text;
  JLabel lbl;

  public TextEg2( String title )
  {  
     super( title );
     text = new JTextField( 15 );
     lbl = new JLabel ( "Enter Your Name:" );
     setLayout( new FlowLayout() );
     add( lbl );
     add( text );
     setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );   
  }

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

QUESTION 7:

(Experiment: ) What happens if the user resizes the frame so that there is not enough room for both the label and the text field?