I have a class of buttons called Keys.java which returns a panel of buttons to the class called Control.java. I have a JLabel in Control.java, but what I want to do is change a JLabel when a button is pressed. How would you go about doing this?
I have tried setting a string in Keys.java which changes based on the button and then setting the JLabel's text equal to the string but it doesn't seem to work.
Any thoughts on how to achieve this?
It may be that you are updating the wrong string or setting the corresponding label's text incorrectly. Both are required. In the example below (using your names), the two updates are tightly coupled in the button's
actionPerformed()
. A more loosely coupled approach is shown here.