JPanel 中实例对象怎么不在JFrame中显示?
请高手指点,哪儿有问题?谢谢!import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
/*
* 应用程序有两个JPanel子类对象和一个按钮,每个JPanel子类
* 对象又有两个按钮和一个标签。*/
public class Test6 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame("MyWindow");
MyJPanel p1=new MyJPanel("确定","取消","标签,我在面板1中");
MyJPanel p2=new MyJPanel("确定","取消","标签,我在面板2中");
JButton b3=new JButton("我是不在面板中的按钮");
f.setSize(500,600);
Container con=f.getContentPane();
con.setLayout(new GridLayout(3,1));
con.add(p1);
con.add(p2);
con.add(b3);
f.setVisible(true);
}
}
class MyJPanel extends JPanel{
MyJPanel(String str1,String str2,String str3){
super();
JPanel p1=new JPanel();
JButton b1=new JButton(str1);
JButton b2=new JButton(str2);
JLabel l1=new JLabel(str3);
p1.add(b1);
p1.add(b2);
p1.add(l1);
p1.setSize(50,150);
}
}