import java.awt.*;
import java.awt.event.*;public class kl implements ActionListener{
      public Button b1;
      public Frame f;
      public static void main(String[]a){
              kl x = new kl();
  x.b1=new Button("first");
              x.f=new Frame("hello");
              x.f.add(x.b1);
  x.f.setSize(100,100);
  x.b1.addActionListener(x);
              x.f.show();
      }   public void actionPerformed(ActionEvent e){
  if (e.getSource() instanceof Button){
  ((Button)e.getSource()).setLabel("seconed");
  }
  }
   
}

解决方案 »

  1.   

    原来还是要用事件监听,我还以为只用action就行呢了,谢谢了!
      

  2.   

    import java.awt.*;public class kl{
          Button b1;
          Frame f;
          public static void main(String[]a){
                  b1=new Button("first");
                  f=new Frame("hello");
                  f.add(b1);
                  f.show();
          }
          public boolean action(Event e,Object o){
                  if(e.target instanceof Button){
                          if(<b>o=="first"</b>){
                                  b1.setLabel("second");
                          }
                  }
        }
    }
    黑体部分不太对
      

  3.   

    同意楼上的。
    o=="first"这句肯定有问题。
      

  4.   

    不会吧,我用o=="first"在applet是可以的,用"first".equals((String)o)也不行!
      

  5.   

    还有,kl x = new kl();是构造实例吗?那么构造函数kl()在哪里呢?
      

  6.   

    还有,kl x = new kl();是构造实例吗?那么,构造函数kl()在那呢?