/*
 *  ==============================================================
 *  DemoBorderLayout.java : Create five buttons and position them 
 *  using a border laygout ....
 * 
 *  Adapted from : Pantham S., Pure JFC Swing, 1999.
 *  Modified by : Mark Austin                          March, 2001
 *  ==============================================================
 */

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

public class DemoBorderLayout extends JApplet {

    Container container = null;

    public void init() {

       //1. Get a handle on the applet's content pane.

       container = this.getContentPane();

       // Note. You don't have to set the border layout becuase
       // content panes use it by default.

       // container.setLayout(new BorderLayout());

       // 2. Give some horizontal and vertical gaps between buttons.

       ((BorderLayout) container.getLayout()).setHgap(2);
       ((BorderLayout) container.getLayout()).setVgap(2);

       // 3. Array that contains border layout constants.

       String[] borderConsts = { BorderLayout.NORTH,
                                 BorderLayout.SOUTH,
                                 BorderLayout.EAST,
                                 BorderLayout.WEST,
                                 BorderLayout.CENTER };

       // 4. Array that contains button names.

       String[] buttonNames = {  "North Button",
                                 "South Button",
                                  "East Button",
                                  "West Button",
                                "Center Button" };

       // 5. Create and add buttons to the container.

       for (int i=0; i<borderConsts.length; i++) {

          JButton button = new JButton(buttonNames[i]);

          // You may wish to reset the preferred size of the east
          // and west buttons to display wide labels.

          if (buttonNames[i] == "East Button" ||
              buttonNames[i] == "West Button") {
              button.setPreferredSize(new Dimension(115, 25)); 
              // width=115, height=25
          }
          container.add(button, borderConsts[i]);
       }
    }
}
