import java.awt.BorderLayout; import java.awt.Color; import javax.swing.*; public class Xiu implements ActionListener{ JFrame f; JPanel p1,p2; JButton b1,b2,b3; public Xiu(){ f=new JFrame(); p1=new JPanel(); p2=new JPanel(); p2.setBackground(Color.gray); b1=new JButton("红色"); b1.addActionListener(this); b2=new JButton("蓝色"); b1.addActionListener(this); b3=new JButton("绿色"); b1.addActionListener(this); p1.add(b1); p1.add(b2); p1.add(b3); f.add(p1,BorderLayout.NORTH); f.add(p2,BorderLayout.CENTER); f.setVisible(true); f.setSize(400, 300); } public static void main(String[] args) { new Xiu(); }