// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class DynamicAdd extends JFrame implements ActionListener {
    private JButton button;
    private int n;

    public DynamicAdd() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().setLayout(new GridLayout(10, 10));
        button = new JButton("Add button");
        button.addActionListener(this);
        getContentPane().add(button);
        pack();
        n = 1;
    }

    public void actionPerformed(ActionEvent ev) {
        if (ev.getSource() == button) {
            getContentPane().add(new JLabel("Label " + n));
            pack();
            n++;
        }
    }

    public static void main(String[] args) {
        DynamicAdd f = new DynamicAdd();
        f.show();
    }
}
