public boolean action(Event e,Object O)
{
if (e.target instanceof Button)
{
Button buttAct=(Button)e.target;
 //修改          if (((String)buttAct.getLable()).equals("Exit"))
System.exit(0);
}
return true;
}

解决方案 »

  1.   

    public boolean action(Event e,Object O)
    {
    if (e.target instanceof Button)
    {
    Button buttAct=(Button)e.target;
     //修改          if (((String)buttAct.getLable()).equals("Exit"))
    System.exit(0);
    }
    return true;
    }
      

  2.   

    还用action啊?
    都快被淘汰的东西了btn.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e)
        {
             System.exit(0);    }
    });
      

  3.   

    Button buttExit=new Button("Exit to system");
    buttExit.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    System.exit(0);
    }
    });
    add(buttExit);
    我这样写,还是出错,我手上的JAVA资料很少,能不能吧这部分写的详细点呀
    谢谢
      

  4.   

    Button buttExit=new Button("Exit to system");
    buttExit.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    System.exit(0);
    }
    });
    add(buttExit);
    我这样写,还是出错,我手上的JAVA资料很少,能不能吧这部分写的详细点呀
    谢谢
      

  5.   

    他给你提示的错误信息是什么啊
    是不是没有实现接口ActionListener 的抽象方法actionPerformed
      

  6.   

    cannot resolve symbol
    symbol  : class ActionListener  
    location: class IpMain
    buttExit.addActionListener(new ActionListener()
                                            ^出错信息
      

  7.   

    cannot resolve symbol
    symbol  : class ActionListener  
    location: class IpMain
    buttExit.addActionListener(new ActionListener()
                                            ^出错信息
      

  8.   

    另外:在action中,
    if (((String)buttAct.getLable()).equals("Exit"))
    也还是出错,提示:
    cannot resolve symbol
    symbol  : class ActionListener  
    location: class IpMain
    buttExit.addActionListener(new ActionListener()
                                        ^
      

  9.   

    用actionPerformed(ActionEvent e),然后把实现这个方法的对象加入所有被监听的button.可以这样实现:
    public calss myclass
    {
       JButton add = new JButton();
       JButton exit = new JButton();
       add.addActionListener(this);
       exit.addActionListener(this);
       public myclass()
       {
       }
       actionPerformed(ActionEvent e)
       {
          Object s=e.getsource();
          if(s==add)
             //执行你的代码
          else if (s==exit)
             //执行你的代码
             ......
       }
    }ok了。试试吧。这就是所谓的java里的时间监听器了。
      

  10.   

    sorry!actionPerformed(ActionEvent e)应该这样写:
    public void actionPerformed(ActionEvent e)
      

  11.   

    kao,还用1.0的老东东,受不了...
      

  12.   

    Object s=e.getsource();
    提示出错:incompatible types
    found   : java.lang.Object
    required: java.awt.Button
    Button buttTmp=event.getSource();
                                                  ^
    1 error
    1 warning
    Finished