Say I have a JButton called b and I:
b.setText(""+someIntVariable)
And I add() it to the appropriate JFrame. If later my program changes the value of someIntVariable will the JButton’s text automatically be updated in my GUI ? Or do I have to do something to update it ?
Once a button is added to the JFrame, it will show the original text that you gave it as a parameter. If you want to change the text, you will need to call
b.setText(""+someIntVariable)again. However, you will not have toaddit to the JFrame.This is because you’re referring to the value stored in
someIntVariable, not to the variable itself. So if the value changes, it will not automatically update.