import java.awt.*;
import javax.swing.*; public class BorderLayoutDemo extends JFrame{ private static final long serialVersionUID = 1L; private JPanel main,north,south,center,east,west; private BorderLayoutDemo(){ main = new JPanel(new BorderLayout(10,10)); //水平和纵向间距设置 north = new JPanel(); south = new JPanel(); center = new JPanel(); east = new JPanel(); west = new JPanel(); this.setSize(600,600); this.setVisible(true); this.setLocation(300, 0); this.add(main); main.add(center); main.add(east,BorderLayout.EAST); main.add(north,BorderLayout.NORTH); main.add(south,BorderLayout.SOUTH); main.add(west,BorderLayout.WEST); north.setBackground(Color.RED); //面板颜色设置 south.setBackground(Color.PINK); east.setBackground(Color.GREEN); west.setBackground(Color.CYAN); center.setBackground(Color.YELLOW); } public static void main(String[] args) { new BorderLayoutDemo(); } }