23 Container类 im port iava. awt public class My PanelDemo extends Frame t Panel pnl=new PanelO public My PanelDemo(String title) super( title);∥设置标题 this inito; public void init(t pnl setsize(100, 100); pnl setBackground(Color,yellow); this. setLayout(null) ∥不设置布局管理器 this setBackground(color blue) this setsize(200, 200); this, add(pn);∥把中间容器添加在顶级容器中 this setVisible(true); public static void main(String args My Panel Demo demo=new My PanelDemo("My PanelDeom! )绪 论 Porgramming in Java 2008.3-2008.7 by Yanjun Zhang,Department of Computer HanDan Collage. 2.3 Container类 import java.awt.*; public class MyPanelDemo extends Frame { Panel pnl=new Panel(); public MyPanelDemo(String title){ super(title); //设置标题 this.init(); } public void init(){ pnl.setSize(100,100); pnl.setBackground(Color.yellow); this.setLayout(null); //不设置布局管理器 this.setBackground(Color.blue); this.setSize(200,200); this.add(pnl); //把中间容器添加在顶级容器中 this.setVisible(true); } public static void main(String args[]){ MyPanelDemo demo=new MyPanelDemo("MyPanelDeom!"); } }