试一下这个:
mouseEventHandler handler=new mouseEventHandler();for(int i=0;i<captions.length;++i)
{
   buttons[i]=new JButton(captions[i]);
   buttons[i].addActionListener(handler);
   buttonPanel.add(buttons[i]);
}private class mouseEventHandler implements ActionListener
{
  public void actionPerformed(ActionEvent e) {
      System.out.println("MouseCLICKED!!"+in);
  }
}

解决方案 »

  1.   

    按钮上的事件处理就是用addActionListener(),不过你可以通过自己重新写一个监听器的
      

  2.   

    晕啊,真的用ActionListener就没有问题了,为什么MouseAdapter就不行?????
      

  3.   

    我试了一下,多块都可以的 。不过按钮只需要实现ActionPerform就可以了 ,这个样子要好很多。
      

  4.   

    都可以,我试过了
    package keystoregui;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    class tmp extends JFrame
    {JButton[] buttons;
      static int in;
      public tmp(){  mouseEventHandler handler=new mouseEventHandler();
    String[] captions={
      "1","2","3","4"
    };
     JPanel   buttonPanel;
     buttonPanel=new JPanel();
          this.getContentPane() .add(buttonPanel);
    for(int i=1;i<captions.length;i++)
      {     JButton buttons=new JButton(captions[i]);
       buttons.addMouseListener(handler);
         buttonPanel.add(buttons);
      }
      this.show() ;
      pack();
      }
      private class mouseEventHandler extends MouseAdapter
      {
        public void mouseClicked(MouseEvent event)
        {
           System.out.println("MouseCLICKED!!"+in);
           in++;
        }
      }
    //  public static void main(String[] args) throws HeadlessException {
        tmp test1 = new tmp();
      }
    }
      //
      

  5.   

    to sean717(翔) 
    晕啊,真的用ActionListener就没有问题了,为什么MouseAdapter就不行?????MouseAdapter是对于Mouse事件的一个监听器的实现,为了方便用户在实现
    MouseListener的时候写所有方法
    ActionListener实际上是只有一个方法的就是ActionPerform,这个如果你看一下设计模式中的Adapter和订阅会明白更多一些