java例程练习(BorderLayou&GridLayout)

import java.awt.*;

public class TestBorderLayout {
	public static void main(String[] args) {
		Frame f = new Frame("Border Layout");
		Button bn = new Button("BN");
		Button bs = new Button("BS");
		Button bw = new Button("BW");
		Button be = new Button("BE");
		Button bc = new Button("BC");

		f.add(bn, BorderLayout.NORTH);
		f.add(bs, BorderLayout.SOUTH);
		f.add(bw, BorderLayout.WEST);
		f.add(be, BorderLayout.EAST);
		f.add(bc, BorderLayout.CENTER);

		f.setSize(600,300);
		f.setVisible(true);
	}

}
import java.awt.*;
public class TestGridLayout {

   public static void main(String[] args) {
   		Frame f = new Frame("GridLayout");

   		for(int i = 0; i < 6; i++) {
   			f.add(new Button("b" + i));
   		}

   		f.setLayout(new GridLayout(3, 2));

   		f.pack();

   		f.setVisible(true);

   }


}


你可能感兴趣的:(layout)