/* This demonstrate a simple Grid Layout Manager * */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class GridLayout extends JFrame { JPanel panel; JButton b1; JButton b2; JButton b3; JButton b4; public GridLayout() { // Sets the title of the window setTitle("Border Layout Mananger"); // Sets the size of the window setSize(300, 400); // Sets the start location of the window setLocationRelativeTo(null); // Sets the action when the window is close setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create a panel with Grid Layout 2 rows and 2 columns panel = new JPanel(); panel.setLayout(new java.awt.GridLayout(2, 2)); // Create the buttons b1 = new JButton("1"); b2 = new JButton("2"); b3 = new JButton("3"); b4 = new JButton("4"); // Add the buttons to the panel panel.add(b1); panel.add(b2); panel.add(b3); panel.add(b4); // Add the panel to the content pane add(panel); // Set the visibility of the window setVisible(true); } public static void main(String[] args) { new GridLayout(); } }