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

public class Swing4 extends JFrame {
    private JButton[] buttons;

    public Swing4() {
        setTitle("Swing4");
        setSize(400,400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        Container pane = getContentPane();
        pane.setLayout(new BorderLayout());

        buttons = new JButton[12];
        for (int i = 0; i < buttons.length; ++i) {
            buttons[i] = new JButton(Integer.toString(i));
        }
        
        JPanel top = new JPanel();
        JPanel bottom = new JPanel();
        JPanel left = new JPanel();
        JPanel right = new JPanel();
        
        pane.add(top, BorderLayout.NORTH);
        pane.add(bottom, BorderLayout.SOUTH);
        pane.add(left, BorderLayout.WEST);
        pane.add(right, BorderLayout.EAST);

        top.setLayout(new FlowLayout());
        bottom.setLayout(new FlowLayout());
        left.setLayout(new FlowLayout());
        right.setLayout(new FlowLayout());
        
        top.add(buttons[0]);
        top.add(buttons[1]);
        left.add(buttons[2]);
        left.add(buttons[3]);
        bottom.add(buttons[4]);
        bottom.add(buttons[5]);
        right.add(buttons[6]);
        right.add(buttons[7]);
        
        JPanel center = new JPanel();
        pane.add(center, BorderLayout.CENTER);
        center.setLayout(new GridLayout(2, 2));
        
        center.add(buttons[8]);
        center.add(buttons[9]);
        center.add(buttons[10]);
        center.add(buttons[11]);
    }

    public static void main(String[] args) {
        Swing4 s = new Swing4();
        s.setVisible(true);
    }
}
