边界布局管理器

import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Test extends JFrame{//把需要的组件全部在这里定义
	JButton an1,an2,an3,an4,an5;
	
	public static void main(String[] args){
		Test lx=new Test();
	}

public Test(){
		an1=new JButton("东方");
		an2=new JButton("西方");
		an3=new JButton("南方");
		an4=new JButton("北方");
		an5=new JButton("中部");
		
		this.add(an1,BorderLayout.EAST);//括号中的参数都是固定的,顺序不能变
		this.add(an2,BorderLayout.WEST);//前面是对象,后面是布局管理器
		this.add(an3,BorderLayout.SOUTH);
		this.add(an4,BorderLayout.NORTH);
		this.add(an5,BorderLayout.CENTER);
		//如果不是五个按钮全部添加,则会以扩充中部为主进行填充,但中部不会被其它四个填充
		
		this.setTitle("边界布局BorderLayout");
		this.setSize(380,320);
		this.setLocation(200,200);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
}

猜你喜欢

转载自blog.csdn.net/WYJ____/article/details/82468963
今日推荐