package com.company; import javax.swing.*; import javax.swing.plaf.basic.BasicOptionPaneUI; import java.awt.*; public class Main extends JFrame { Main(){ setBounds(100,100,350,200); setDefaultCloseOperation(EXIT_ON_CLOSE); Container c=getContentPane(); c.setLayout(new BorderLayout());//设置为边界布局 JButton b1=new JButton("中"),//为边界起名字 b2=new JButton("西"), b3=new JButton("东"), b4=new JButton("南"), b5=new JButton("北"); c.add(b1,BorderLayout.CENTER);//中部添加按钮 c.add(b2,BorderLayout.EAST); c.add(b3,BorderLayout.WEST); c.add(b4,BorderLayout.SOUTH); c.add(b5,BorderLayout.NORTH); setVisible(true); } public static void main(String[] args) { new Main(); // write your code here } }