import java.awt.*;
import java.awt.event.*;public class TextField
{
public static void main(String args[])
{
fframe ff = new fframe("go on!",400,400,400,400);

}
}class fframe extends Frame
{
fframe(String s,int x,int y,int w,int h)
{
super(s);
setBounds(x,y,w,h);

TextField t = new TextField();
add(t);

t.addActionListener(new monitor());


setVisible(true);
}


}class monitor implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
TextField tt = (TextField)e.getSource();
System.out.println(tt.getText());
tt.setText(" ");
}
}为什么会提示TextField找不到符号呢???

解决方案 »

  1.   

    class fframe extends Frame
    {
    //private Panel p1,p11,p2,p22;
    fframe(String s,int x,int y,int w,int h)
    {
    super(s);

    setBounds(x,y,w,h);
    TextField tf = new TextField();
    add(tf);
    setVisible(true);
    }
    }这样也不行,会提示 add(tf)找不到符号!!
      

  2.   

    你自己的类名TextField 和awt中的TextField冲突了。
      

  3.   


    谢谢`
    ls的请向ZangXT 学习`
      

  4.   

    import java.awt.*;
    import java.awt.event.*;public class Main {    public static void main(String args[]) {
            FFrame ff = new FFrame("go on!", 400, 400, 400, 400);
        }
    }class FFrame extends Frame {    FFrame(String s, int x, int y, int w, int h) {
            super(s);
            setBounds(x, y, w, h);
            TextField t = new TextField();
            add(t);
            t.addActionListener(new Monitor());
            addWindowListener(new WindowAdapter() {            @Override
                public void windowClosing(WindowEvent e) {
                    dispose();
                    System.exit(0);
                }
            });
            setVisible(true);
        }
    }class Monitor implements ActionListener {    public void actionPerformed(ActionEvent e) {
            TextField tt = (TextField) e.getSource();
            System.out.println(tt.getText());
            tt.setText(" ");
        }
    }