I am writing a small Java app (on Windows, hence the _on_vista appended to my name).
I got 3 buttons, all of which will react to a click event, but do different things.
Is the following code the accepted way or is there a cleaner way I do not know about? On one half, it works, on the other half, something doesn’t seem right…
Thanks
cool_button_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { coolfunction1(); } }); cool_button_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { coolfunction2(); } }); // etc ...
The functions that get called will spawn off threads as needed, so on and so forth.
UPDATE – Both were good (pretty much the same) answers. I accepted the one with the lower rep to share the wealth. Thanks again guys.
Yes, this is the correct way to do this. It’s a bit clumsy (to have to write five long lines of code just to be able to call a method) but that’s Java 🙁