import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 public class GridLayoutTest extends JFrame implements ActionListener
 {
 private JButton B[];
 private String S[]={"Button 1","Button 2","Button 3",
 "Button 4","Button 5","Button 6"};

 public GridLayoutTest(String s)
 {
 super(s);
 setLayout(new GridLayout(3,2,5,5));
 B=new JButton[6];
 for(int i=0;i<B.length;i++)
 {
 B[i]=new JButton(S[i]);
 B[i].addActionListener(this);
 add(B[i]);
 }
 }

 public void actionPerformed(ActionEvent e)
 {
 for(int i=0;i<B.length;i++)
 {
 if(e.getSource()==B[i])
 B[i].setVisible(false);
 else B[i].setVisible(true);
 }
 validate();
 }
      public static void main(String[] args)
      {
        GridLayoutTest f = new GridLayoutTest("Grid Layout formattting of Graphic User Interphase (GUI)");
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        f.setSize(800,500);
        f.setVisible(true);    
      }
 }
