class Demo extends JFrame implements TextListener
{
   JTextField text = new JTextField(15);
   
   class Demo()
   {
        this.add(text);
        
        this.addTextListener(this);    //    有没有这个方法阿?监听文本区内容变化的应该是这个类吧,方法怎么写啊,这样写有错误
 
        this.pack();
        this.show();
   }   public void textValueChanged(TextEvent e)
   {
      System.out.println ("怎样写啊???");
   }
   public static void main(String s[])
   {
         new Demo();
   }
}

解决方案 »

  1.   

    通常还是写成内部类的形式吧:
    this.addTextListener(new TextListener(){
       public void textValueChanged(TextEvent e)
       {
          System.out.println ("怎样写啊???");
       }
    });
      

  2.   

    class Demo()
     {
            this.add(text);
            
            this.addTextListener(this);    //   这个方法应该是什么?我写这个不对啊
     }
      

  3.   

    text.addListener(new Listener(){
       public void textValueChanged(TextEvent e)
       {
          System.out.println ("怎样写啊???");
       }
    });