多个按钮使用同一个事件处理过程,怎么知道是哪一个按钮触发的?我的按钮是在程序运行中动态增加的,是一个按钮数组,事件处理过程被指定给该按钮数组后,根据所点按钮的不同,应该执行不同的逻辑。           public void mouseExited(MouseEvent e)
     {
     //int i=(e.getX()-329+83)/83;
     // int j=(e.getY()-217+84)/84;
     // if(i>=1&&i<=3&&j>=0&&j<=4)
     // {
     e.getSource().setBorderPainted(false);
     // }
     }这样子问什么不对呢(进入按钮则显示边框,出去则消除,数组里每生成一个一个按钮是给它加mouselistener)

解决方案 »

  1.   

    ((JButton) e.getSource()).setBorderPainted(false);
      

  2.   

    意思是说前面加个转换类型的吗?我后来只好循环一个个比较:
                                for(int i=0;i<4;i++)
         for(int j=0;j<4;j++)
         {
         if(J[i][j]==e.getSource())
         {
         J[i][j].setBorderPainted(false);
         break;
         }
         }
    还有请教一下:Component.getComponentAt(i,j).setBorderPainted(true);这样调用在  静态非静态上出错,可不可以问下哪里有Component.getComponentAt(i,j)比较详细的啊(sagezk  多谢你啊,加个好友)
      

  3.   

    jbutton里面有一个actioncommand,你看看搜了一篇文章
    http://academicjava.com/Java_help/Tutorial_Examples_Swing_0.html