Java adiciona botões dinamicamente como uma matriz [duplicada]

Duplicata Possível:
java - Como eu adicionaria dinamicamente o componente swing ao gui ao clicar?

Eu quero adicionar matriz de botões dinamicamente. Eu tentei assim:

this.pack();
    Panel panel = new Panel();
    panel.setLayout(new FlowLayout());
    this.add(panel);
    panel.setVisible(true);
    for (int i = 0; i < Setting.length; i++) {
        for (int j = 0; j < Setting.width; j++) {
            JButton b = new JButton(i+"");
            b.setSize(30, 30);
            b.setLocation(i * 30, j * 30);
            panel.add(b);
            b.setVisible(true);
        }
    }

mas não entendi nada, qual erro eu cometi?

Editar

Eu tenho "escolhas" de classe jFrame nele eu tenho um botão, quando eu pressiono o botão, isso deveria acontecer:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
       structure.Setting s = new Setting(8, 8, 3, 1, 1);
       Game g = new Game();
       g.setSetting(s);
       this.dispose();
       g.show();
    }

então eu vou para a classe Game (também da classe jFrame) para a função setSetting e é assim:

void setSetting(Setting s) {
        this.setting = s;
        structure.Game game = new structure.Game(setting);
        JPanel panel = new JPanel(new GridLayout(5, 5, 4, 4));
        for (int i = 1; i <= 5; i++) {
            for (int j = 1; j <= 5; j++) {
                JButton b = new JButton(String.valueOf(i));
                panel.add(b);
            }
        }
        add(panel);
        pack();
        setVisible(true);
    }
    structure.Setting setting;
}

questionAnswers(4)

yourAnswerToTheQuestion