importjava.awt.Graphics;importjavax.swing.JFrame;importjavax.swing.JPanel;/*** 扩展于JPanel的类,重写paintComponent方法
* jdk 5.0
*@author左杰
**/publicclassExample4FrameextendsJFrame{/****/privatestaticfinallongserialVersionUID=1L;publicExample4Frame(){
setTitle("JPanel应用实例");
setSize(300,200);//创建panel对象,并添加到窗体Example4Panel panel=newExample4Panel();
add(panel);
}publicstaticvoidmain(String[] args){
JFrame frame=newExample4Frame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}classExample4PanelextendsJPanel{/****/privatestaticfinallongserialVersionUID=1L;publicvoidpaintComponent(Graphics g){super.paintComponents(g);
g.drawString("练习JPanel的应用",100,75);//panel面板中添加文本}
}