1 package Layout; 2 import java.awt.*; 3 import javax.swing.*; 4 public class MyJPanel extends JFrame { 5 private JPanel p1 = new JPanel();//面板默认流式布局 6 private JPanel p2 = new JPanel(); 7 private JButton b1 = new JButton("B1"); 8 private JButton b2 = new JButton("B2"); 9 private JButton b3 = new JButton("B3"); 10 private JButton b4 = new JButton("B4"); 11 private JButton b5 = new JButton("B5"); 12 public MyJPanel(){ 13 this.setTitle("用户界面"); 14 this.setSize(500, 300); 15 this.setLocation(600,400); 16 p1.add(b1); 17 p1.add(b2); 18 p2.add(b4); 19 p2.add(b5); 20 this.add(p1,BorderLayout.NORTH); 21 this.add(b3,BorderLayout.CENTER); 22 this.add(p2,BorderLayout.SOUTH); 23 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 24 this.setVisible(true); 25 26 27 } 28 public static void main(String[] args) { 29 MyJPanel l = new MyJPanel(); 30 31 } 32 33 }