Hey all I am a month or two in coding in java and currently I am doing a java calculator gui project, my professor requires us to code the gui by hand, and I did so with a panel and gridbaglayout layout manager, anyways since this is a calculator I have a plethora of buttons to listen to during program execution, I ask how do I perform tasks accordingly with each button?
Do I create an actionlistener class or mouselistener class? and with each button I have, do I assign a unique class for each button component I have? i.e: one class for the button 1, one class for the addition addition button and so on.
Or can I just, (as I have been planning earlier) create one action or mouselistener class and override the existing actionPerformed method in the original class to be implemented and use it for the whole of my buttons.
I do not however know how to perform the latter approach. Although, I have this vague idea that my actionPerformed method will have like, a case statement that reads the currently pressed button, although I do not know how to detect the currently pressed button.
A little background on my code: I have stored all digit buttons (i.e 0 - 9) in an array list of buttons for easy access, I have also stored all calculator functions in a nother arraylist of buttons with their own equivalent identifier in an enum I have created.
That is all, thank you for the help and for reading this lengthy post.