import java.awt.*; public class JanelaGrid extends Frame { private final int rows=3, cols=4; public JanelaGrid() { setTitle("GridLayout"); setSize(240,100); setLayout(new GridLayout(rows, cols)); } public void addButton(int count) { int max = rows*cols; if (count < max) max = count; for(int i=1; i <= max; ++i) add(new Button("B"+i)); } public static void main(String[] args) { JanelaGrid j = new JanelaGrid(); int qtde = 10; try { if (args.length > 0) qtde = Integer.parseInt(args[0]); } catch (Exception e) { } j.addButton(qtde); j.validate(); j.setVisible(true); } }