I am creating a swing program which basically has a lot of buttons, and I was thinking that instead of adding the listener individually to each button, if I could add the listener to the JPanel instead, and read the events using .getSource() function, things would be a whole lot easier? Is it possible?
I am creating a swing program which basically has a lot of buttons, and
Share
Adding a listener to a component doesn’t mean that you are also adding that listener to the internal components. Instead, think of using groups of buttons (e.g. a button array)
and add the listener to all buttons with one iteration.