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

public class BunchOfButtons2 extends JFrame {
    public BunchOfButtons2() {
        super("Buttons!");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        JPanel buttonPanel = new JPanel();
        for(int i = 0; i < 10; ++i) {
            final JButton button = new JButton("Button " + i);
            button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Clicked on " + button.getText());
                    }
                });
            buttonPanel.add(button);
        }

        getContentPane().add(buttonPanel);
        pack();
    }
        
    public static void main(String[] args) {
        new BunchOfButtons2().setVisible(true);
    }
}