import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Demo1 extends JFrame { private JButton[] a = new JButton[6]; private String[] s = {"小二","小三","小中","下一","下二","下三"}; private static JPanel uPanel = new JPanel(); private static JPanel cPanel = new JPanel(); private static JPanel dPanel = new JPanel(); public Demo1(){ uPanel.setLayout(new FlowLayout()); dPanel.setLayout(new FlowLayout()); btnInit(); cPanel.add(a[2]); getContentPane().add(uPanel,BorderLayout.NORTH); getContentPane().add(dPanel,BorderLayout.SOUTH); getContentPane().add(cPanel,BorderLayout.CENTER); pack(); } public void btnInit(){ for(int i = 0;i<a.length;i++){ a[i] = new JButton(s[i]); if(i<=1){ uPanel.add(a[i]); } if(i>=3){ dPanel.add(a[i]); } } } public static void main(String[] args) { new Demo1().setVisible(true); } }