日期:2014-05-20  浏览次数:20746 次

虚心请教~~~小弟实在没法了........
我是新手正在学习中。。。。。。
这是个简单的程序,还没写完但是应该可以看到程序界面了呀,为什么编译的时候没问题,运行的时候就出问题了啊???大哥大姐教教我呀。。。谢谢。。。。

java.lang.IllegalArgumentException:   adding   container 's   parent   to   itself
                at   java.awt.Container.addImpl(Container.java:1005)
                at   java.awt.Container.add(Container.java:899)
                at   Calculator.init(Calculator.java:21)
                at   Calculator.main(Calculator.java:128)
Press   any   key   to   continue...

-----------------以下是程序-----------------------------

import   java.awt.*;
import   java.awt.event.*;
import   javax.swing.*;
import   java.awt.event.ActionListener;
import   java.util.EventListener;
public   class   Calculator   extends   JFrame   implements   ActionListener  
{
JTextField   jtf=   new   JTextField();
public   void   init()
{
JFrame   tf=new   JFrame();
Container   c=tf.getContentPane();
tf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jtf.setHorizontalAlignment(JTextField.RIGHT);
c.add(tf, "NORTH ");
JPanel   jpl=new   JPanel();
c.add(jpl, "CENTER ");
//---------------------------------------------
jpl.setLayout(new   GridLayout(4,4));
//--------------------------------------------
JButton   b=null;

b=   new   JButton( "1 ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( "2 ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( "3 ");
b.addActionListener(this);
jpl.add(b);

b=   new   JButton( "+ ");
b.addActionListener(this);
jpl.add(b);

b=   new   JButton( "4 ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( "5 ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( "6 ");
b.addActionListener(this);
jpl.add(b);

b=   new   JButton( "- ");
b.addActionListener(this);
jpl.add(b);

b=   new   JButton( "7 ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( "8 ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( "9 ");
b.addActionListener(this);
jpl.add(b);

b=   new   JButton( "* ");
b.addActionListener(this);
jpl.add(b);

b=   new   JButton( "0 ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( ". ");
b.addActionListener(this);
jpl.add(b);


b=   new   JButton( "= ");
b.addActionListener(this);
jpl.add(b);

b=   new   JButton( "\\ ");
b.addActionListener(this);
jpl.add(b);

tf.setSize(400,400);
tf.setTitle( "计算器 ");
tf.setVisible(true);
}

public   void   actionPerformed(ActionEvent   e)