边框布局BorderLayout
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package x_012;
import java.awt.*;
import javax.swing.*;
/**
*边框布局,分东南西北中,五部分。
* @author Administrator
*/
public class XBorderLayout extends JFrame{
public XBorderLayout(){
super("XBorderLayout");
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
BorderLayout flo=new BorderLayout();
setLayout(flo);
JButton panic=new JButton("North");
JButton dont=new JButton("South");
JButton blame=new JButton("Centre");
JButton save=new JButton("East");
JButton med=new JButton("West");
add(panic,BorderLayout.NORTH);//添加按钮时要注意说明要添加进布局的哪个方位
add(dont,BorderLayout.SOUTH);
add(save,BorderLayout.CENTER);
add(blame,BorderLayout.EAST);
add(med,BorderLayout.WEST);
}
public Insets getInsets(){ //重写getInsets构造函数。设置组件与容器的边距
Insets squeeze=new Insets(100,80,30,80); //逆时针顺序,上左下右
return squeeze;//注意没有类型也可以返回。!!!
}
//Insets around= new Insets(10,6,3,15);
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
XBorderLayout sal=new XBorderLayout();
}
}
运行截图: