//*******************************************************************
//
//   Grid_Bag.java          In Text          Applet
//
//   Authors:  Lewis and Loftus
//
//   Classes:  Grid_Bag
//
//*******************************************************************

import java.applet.Applet;
import java.awt.*;

//-------------------------------------------------------------------
//
//  Class Grid_Bag demonstrates the grid bag layout manager.
//
//  Methods:
//
//     private void first_row (Button button)
//     private void second_row (Button button1, Button button2)
//     private void third_row (Button button)
//     private void forth_row (Button button)
//     public void init()
//
//-------------------------------------------------------------------

public class Grid_Bag extends Applet {

   private Button button1 = new Button ("I");
   private Button button2 = new Button ("think");
   private Button button3 = new Button ("therefore");
   private Button button4 = new Button ("I");
   private Button button5 = new Button ("am");

   private GridBagLayout gridbag = new GridBagLayout();

   //===========================================================
   //  Sets up the first row of the grid bag layout.
   //===========================================================
   private void first_row (Button button) {

      GridBagConstraints constraints = new GridBagConstraints();

      constraints.gridwidth = GridBagConstraints.REMAINDER;
      constraints.anchor    = GridBagConstraints.WEST;

      gridbag.setConstraints (button, constraints);
      add (button);

   }  // method first_row

   //===========================================================
   //  Sets up the second row of the grid bag layout.
   //===========================================================
   private void second_row (Button button1, Button button2) {

      GridBagConstraints constraints = new GridBagConstraints();

      constraints.gridwidth = 8;
      constraints.fill      = GridBagConstraints.HORIZONTAL;
      constraints.weightx   = 1.0;

      gridbag.setConstraints (button1, constraints);
      add (button1);

      constraints = new GridBagConstraints();

      constraints.gridwidth = GridBagConstraints.REMAINDER;
      constraints.fill      = GridBagConstraints.VERTICAL;
      constraints.weighty   = 1.0;

      gridbag.setConstraints (button2, constraints);
      add (button2);

   }  // method second_row

   //===========================================================
   //  Sets up the third row of the grid bag layout.
   //===========================================================
   private void third_row (Button button) {

      GridBagConstraints constraints = new GridBagConstraints();

      constraints.gridwidth = GridBagConstraints.REMAINDER;
      constraints.fill      = GridBagConstraints.BOTH;
      constraints.weighty   = 1.0;

      gridbag.setConstraints (button, constraints);
      add (button);

   }  // method third_row

   //===========================================================
   //  Sets up the fourth row of the grid bag layout.
   //===========================================================
   private void forth_row (Button button) {

      GridBagConstraints constraints = new GridBagConstraints();

      constraints.gridwidth = GridBagConstraints.REMAINDER;

      gridbag.setConstraints (button, constraints);
      add (button);

   }  // method forth_row

   //===========================================================
   //  Sets up each row of the grid bag layout using various
   //  buttons.
   //===========================================================
   public void init() {

      setLayout(gridbag);

      first_row (button1);
      second_row (button2, button3);
      third_row (button4);
      forth_row (button5);

//    setVisible(true);
	show(true);

   }  // method init

}  // class Grid_Bag


