急用!!!!
有这么一个设置为什么出现下面的错误?
Exception in thread "main "
java.lang.IllegalArgumentException: adding a window t
o a container
at java.awt.Container.addImpl(Container.java:1010)
at java.awt.Container.add(Container.java:364)
at JieMian. <init> (JieMian.java:46)
at JieMian.main(JieMian.java:61)
我是在一个面板里面添加了一个窗口
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class JieMian extends JFrame implements ActionListener
{
ShuJuJieMianGUI shuju=null;
//SanWeiTuXingGUI tuxing=null;
JMenuBar mb;
JMenu menu;
JMenuItem Reading,Drawing,exit;
JLabel label=null;
JPanel pCenter;
CardLayout layout=null;
public JieMian()
{
mb=new JMenuBar();
mb.setOpaque(true);
menu=new JMenu( "功能选择 ");//gong neng xuan ze
Reading=new JMenuItem( "读入DEM数据 ");//du ru DEM shu ju
Drawing=new JMenuItem( "DEM数据三位显示 ");//DEM shu ju de san wei xian shi
exit=new JMenuItem( "退出 ");//tui chu an liu
menu.add(Reading);
menu.add(Drawing);
menu.addSeparator();
menu.add(exit);
mb.add(menu);
setJMenuBar(mb);
label=new JLabel( "我的三维DEM显示程序 ",JLabel.CENTER);
label.setFont(new Font( "楷体_GB2312 ",Font.BOLD,30));//she ji zi ti
label.setForeground(Color.blue);
shuju=new ShuJuJieMianGUI();
Container c=this.getContentPane();//rong qi
pCenter=new JPanel();//mian ban
layout=new CardLayout();//bu ju ge shi
c.add(pCenter, "Center ");//rong qi li mian tian jia mian ban
pCenter.setLayout(layout);//mian ban de bu ju ge shi
pCenter.add( "WELCOME MODE ",label);
pCenter.add( "READING MODE ",shuju);//错误出在这个地方
//pCenter.add( "DRAWING MODE ",tuxing);
this.setBounds(0,0,800,650);
this.setTitle( "我的毕业论文程序 ");//she zhi biao ti
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.validate();
exit.addActionListener(this);
Reading.addActionListener(this);
}
public static void main(String[] args)
{
new JieMian();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==exit)
{
System.exit(0);
}
else if(e.getSource()==Reading)
{
layout.show(pCenter, "READING MODE ");
}
}
}
class ShuJuJieMianGUI extends JFrame
{
Object[][] ShuJuInfo={{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
Object[] ShuJuName={ "X ", "Y ", "Z "};
JTable table;
JScrollPane sp;