下面这个程序运行发生异常:Exception in thread "main" java.lang.IllegalArgumentException: adding container's parent to itself
import java.awt.*;
import java.awt.event.*;
public class Chat {
Frame f=new Frame("我的聊天室");
TextField tfIP=new TextField(15);
List lst=new List(6);
public static void main(String [] args)
{
Chat chat=new Chat();
chat.init();
}
private   void init() {
f.setSize(300,300);
f.add(lst);
Panel p=new Panel();
p.setLayout(new BorderLayout());
p.add("West",tfIP);
TextField tfData=new TextField(20);
p.add("East",tfData);
p.add("South",p);
f.setVisible(true);
f.setResizable(false);
f.addWindowListener(new WindowAdapter()
{
public void WindowClosing(WindowEvent e)
{
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
tfData.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
((TextField)e.getSource()).setText("");
}
});
}
}