好像事件有个GetSource的方法,可以确定是那个对象发出的事件,和Button1或2比一下就像了。

解决方案 »

  1.   

    如果监听不同类触发的时间,可以用instanceof这个东东。
      

  2.   

    是事件处理么如果是
    getSource()可以getActionCommand(),也可以
    public void actionPerformed(ActionEvent e)
    {
     if(e.getSource()==button1){处理    };
    }
    或getActionCommand()获取,按钮名称
    JButton b1=new JButton("ddd");
    public void actionPerformed(ActionEvent e)
    {
     if(e.getActionCommand()).equals("ddd")
      {处理    };
    }
      

  3.   

    public class test implements ActionListener {
    …………
    public void actionPerformed(ActionEvent e) {
    JButton jb=(JButton)e.getSource();
    if(jb==jb1)
    …………
    if(jb==jb2)
    ………………
    }
    }