1 // Fig. 10.48: Grid.java 2 // Demonstrating GridLayout. 3 import java.applet.Applet; 4 import java.awt.*; 5 6 public class Grid extends Applet { 7 private Button button1, button2, button3, 8 button4, button5; 9 10 public void init() 11 { 12 // instantiate button objects 13 button1 = new Button( "one" ); 14 button2 = new Button( "two" ); 15 button3 = new Button( "three" ); 16 button4 = new Button( "four" ); 17 button5 = new Button( "five"); 18 19 // set layout to grid layout 20 setLayout( new GridLayout( 2, 3 ) ); 21 22 // order is important 23 add( button1 ); // row 1 column 1 24 add( button2 ); // row 1 column 2 25 add( button3 ); // row 1 column 3 26 add( button4 ); // row 2 column 1 27 add( button5 ); // row 2 column 2 28 } 29 }