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

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

/** An example of GridBagLayout. This is actually
 *  relatively simple as far as GridBagLayout usage
 *  goes.
 */

public class GridBagTest extends Applet {
  private GridBagLayout layout;
  private GridBagConstraints constraints;

  public void init() {
    layout = new GridBagLayout();
    setLayout(layout);
    constraints = new GridBagConstraints();
    Label buttonLabel = new Label("Buttons");
    setPosition(buttonLabel, 0, 0, 1, 1, 0, 100,
                GridBagConstraints.VERTICAL);
    add(buttonLabel);
    Button button1 = new Button("Button One");
    setPosition(button1, 0, 1, 1, 1, 0, 100,
                GridBagConstraints.BOTH);
    add(button1);
    Button button2 = new Button("Button Two");
    setPosition(button2, 0, 2, 1, 1, 0, 100,
                GridBagConstraints.BOTH);
    add(button2);
    Button button3 = new Button("Button Three");
    setPosition(button3, 0, 3, 1, 1, 0, 100,
                GridBagConstraints.BOTH);
    add(button3);
    Button button4 = new Button("Button Four");
    setPosition(button4, 0, 4, 1, 1, 0, 100,
                GridBagConstraints.BOTH);
    add(button4);
    Button button5 = new Button("Button Five");
    setPosition(button5, 0, 5, 1, 1, 0, 100,
                GridBagConstraints.BOTH);
    add(button5);
    Label restLabel
      = new Label("Everything Else");
    setPosition(restLabel, 1, 0, 2, 1, 100, 100,
                GridBagConstraints.VERTICAL);
    add(restLabel);
  }

  /** If you use GridBagLayout, you'll want a helper
   *  method like this to help set values in
   *  the GridBagConstraints object.
   */
  
  public void setPosition(Component component,
                          int x, int y,
                          int width, int height,
                          int weightx, int weighty,
                          int fill) {
    constraints.weightx = 100;
    constraints.weighty = 100;
    constraints.gridx = x;
    constraints.gridy = y;
    constraints.gridwidth = width;
    constraints.gridheight = height;
    constraints.weightx = weightx;
    constraints.weighty = weighty;
    constraints.fill = fill;
    layout.setConstraints(component, constraints);
  }
}

