import java.awt.*;
import javax.swing.*;

/** This illustrates the effect of specifying 0 for the number
 *  of columns. The number of rows is read from the command line
 *  (default 2), and the column number is chosen by the system
 *  to get as even a layout as possible.
 *
 *  Taken from Core Web Programming from 
 *  Prentice Hall and Sun Microsystems Press,
 *  http://www.corewebprogramming.com/.
 *  &copy; 2001 Marty Hall and Larry Brown;
 *  may be freely used or adapted.
 */

public class ElevenButtons extends JPanel {
  public ElevenButtons(int numRows) {
    setLayout(new GridLayout(numRows, 0));
    for(int i=0; i<11; i++) {
      add(new JButton("Button " + i));
    }
  }

  public static void main(String[] args) {
    int numRows = 2;
    if (args.length > 0) {
      numRows = Integer.parseInt(args[0]);
    }
    String title = "11 Buttons using GridLayout(" +
                   numRows + ",0).";
    WindowUtilities.setNativeLookAndFeel();
    WindowUtilities.openInJFrame(new ElevenButtons(numRows),
                                 550, 200, title);
  }
}
