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


/** DemoGridLayout - program to demonstrate the
* <code>GridLayout</code> class.<p>
*
* Usage:<p>
*
* <pre>
*     java DemoGridLayout arg1
*
*     where 'arg1' = strut size in pixels
* </pre>
*
* @see <a href="DemoGridLayout.java">source code</a>
* @author Scott MacKenzie, 2002
* @author William Soukoreff, 2012
*/
public class DemoGridLayout extends JFrame
{
   public static void main(String[] args)
   {
      if (args.length != 1)
      {
         usage();
         return;
      }

      int strutSize = Integer.parseInt(args[0]);

      // use look and feel for my system (Win32)
      try {
         UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
      } catch (Exception e) {}

      DemoGridLayout frame = new DemoGridLayout(strutSize);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setTitle("DemoGridLayout");
      frame.pack();
      frame.setVisible(true);
   }

   private static void usage()
   {
      System.out.println(
         "usage: java DemoGridLayout arg1\n\n" +
         "where 'arg1' = strut size in pixels"
      );
      return;
   }



   private JButton b1;
   private JButton b2;
   private JButton b3;
   private JButton b4;
   private JButton b5;

   public DemoGridLayout(int strutArg)
   {
      // ----------------------------------
      // construct and configure components
      // ----------------------------------

      b1 = new JButton("Carrot");
      b2 = new JButton("Yam");
      b3 = new JButton("Broccoli");
      b4 = new JButton("Brussel Sprouts");
      b5 = new JButton("Zucchini");

      // -----------------
      // layout components
      // -----------------

      JPanel panel = new JPanel();

      // use GridLayout with struts, as per command-line arg
      int hGap = strutArg;
      int vGap = strutArg;
      panel.setLayout(new GridLayout(3, 2, hGap, vGap));

      panel.add(b1);
      panel.add(b2);
      panel.add(b3);
      panel.add(b4);
      panel.add(b5);

      // try this...
      //panel.setPreferredSize(new Dimension(175, 175));

      // try this...
      //System.out.println("panel : " + panel.getPreferredSize());

      // make panel this JFrame's content pane

      setContentPane(panel);

   }
}


