import java.awt. * ; public class TestPanel ... { public static void main(String args[]) ...{ Frame f = new Frame("Java Frame with Panel"); Panel p = new Panel(null); f.setLayout(null); //设置布局管理的方式,frame 的默认布局为 BorderLayout f.setBounds(300,300,500,500);//设置frame的大小, f.setBackground(new Color(0,0,102));//设置frame的背景色 p.setBounds(50,50,400,400);//设置panel的大小 p.setBackground(new Color(204,204,255));//设置panel的背景色 f.add(p); f.setVisible(true); }}