1import java.awt.GridLayout;
2
3import javax.swing.JApplet;
4import javax.swing.JButton;
5import javax.swing.JFrame;
6
7public
8 class GridLayoutApplet extends JApplet {
9 JFrame f;
10 public void init() {
11 f = new MyGridFrame();
12 f.setVisible(true);
13 }
14 }
15
16class MyGridFrame extends JFrame {
17 public MyGridFrame() {
18 setTitle("Grid Layout Demo");
19 setSize(300, 300);
20 setLayout(new GridLayout(2,4));
21 add(new JButton("yellow"));
22 add(new JButton("magenta"));
23 add(new JButton("red"));
24 add(new JButton("green"));
25 add(new JButton("blue"));
26 add(new JButton("black"));
27 add(new JButton("white"));
28 pack();
29 }
30}