Attaching A Single Action Listener To All Buttons

后端 未结 4 2034
孤街浪徒
孤街浪徒 2020-11-29 13:07

I have a program with many buttons, all of which will be performing the same function. I was wondering if there was a way to attach a single listener to all existing JButton

4条回答
  •  -上瘾入骨i
    2020-11-29 13:44

    You Could...

    Create a single instance of the ActionListner and apply it to all the buttons

    You Could...

    Make use if the Actions API, which will allow you to create a self contained ActionListerner, which also includes the details to configure the buttons as well.

提交回复
热议问题