I have many GUI forms with many buttons on each GUI form. I am wanting to detect when a user clicks on any of these buttons.
My question is this: Should I add code individually to each button, or can I cater to each button press by a public method that is called whenever a button is pressed? If I use a public method (that I would rather do), how does the method detect the button that called the function? Do the buttons have to be a public variable?
Currently I am using this code (that works, I am wondering if I can do it better):
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
System.out.println("You clicked the button");
}});