Add action to a JButton created by another JButton

前端 未结 3 1431
忘了有多久
忘了有多久 2021-01-24 10:39

I have a Jbutton that when pressed creates another button and the new button is added to the panel. How to I add an actionListener to the new button?

For example:

3条回答
  •  耶瑟儿~
    2021-01-24 11:16

    The newButton instance needs to have its actionPerformed method filled out. I see that you have an ActionListener added to the button, but that just means that someone is listing for actions. The code you show above doesn't define any actions on that newButton, so therefore there's no events being fired, and the ActionListener never gets notified of anything.

提交回复
热议问题