L Ze wrote:(...) it only clear the text in the label but doesn't add it back to Total Coins?
Paweł Baczyński wrote:Welcome to the Ranch!
L Ze wrote:(...) it only clear the text in the label but doesn't add it back to Total Coins?
There is no code in your method that could add anything to "Total Coins" so how can you expect something to be added to "Total Coins"?
I think we'd have to see more of your code.L Ze wrote:
Paweł Baczyński wrote:Welcome to the Ranch!
L Ze wrote:(...) it only clear the text in the label but doesn't add it back to Total Coins?
There is no code in your method that could add anything to "Total Coins" so how can you expect something to be added to "Total Coins"?
Hi Paweł, thanks for the welcome but I'm not sure how to do the add code statement as I'm a beginner and only followed this guide for the reset button
All things are lawful, but not all things are profitable.
Knute Snortum wrote:All your code does is clear the text of the coins widget, which I suspect is a JLabel. You probably have a variable for total coins somewhere that you use to display the total (495 in your example). You should set total coins to zero, then set the coins label's text to "Total Coins" + totalCoins
If that doesn't work, post more code for us to look at.
All things are lawful, but not all things are profitable.
Knute Snortum wrote:All your code does is clear the text of the coins widget, which I suspect is a JLabel. You probably have a variable for total coins somewhere that you use to display the total (495 in your example). You should set total coins to zero, then set the coins label's text to "Total Coins" + totalCoins
If that doesn't work, post more code for us to look at.
Carey Brown wrote:Seems like you'd want to set totalcoins to 500 and ocoins to zero. That would reset you back to the starting state. Also, you'd have to reset the matching text fields as well.
You don't need to 'add' all the points back you just need totalcoins=500.L Ze wrote:
Carey Brown wrote:Seems like you'd want to set totalcoins to 500 and ocoins to zero. That would reset you back to the starting state. Also, you'd have to reset the matching text fields as well.
Yes, the total coins is 500 and ocoins is 0 as that's the starting point, each time I press the add button, it will take a coin from the total points and add it to ocoin label however I don't know the missing code that should be under this code so once I press the Reset button, it will add all the points I have taken back to total points,
Carey Brown wrote:
You don't need to 'add' all the points back you just need totalcoins=500.L Ze wrote:
Carey Brown wrote:Seems like you'd want to set totalcoins to 500 and ocoins to zero. That would reset you back to the starting state. Also, you'd have to reset the matching text fields as well.
Yes, the total coins is 500 and ocoins is 0 as that's the starting point, each time I press the add button, it will take a coin from the total points and add it to ocoin label however I don't know the missing code that should be under this code so once I press the Reset button, it will add all the points I have taken back to total points,
All things are lawful, but not all things are profitable.
Knute Snortum wrote:Post your code. We don't know what "when I try" means.
Just as a guess, coins.setText("") does not do anything to ocoins or totalcoins.
Carey Brown wrote:After setting totalcoins to 500 you'll need to call
in order to update the display.
L Ze wrote:I mean that when I run the project to test the code I posted earlier on, the total coins value doesn't return to 500 when I press the clear button but only clears the ocoins label for example, I've 10 in the ocoins label when I click clear the total coins value is at 490 but it should be at 500
All things are lawful, but not all things are profitable.
Carey Brown wrote:After setting totalcoins to 500 you'll need to call
in order to update the display.
Carey Brown wrote:
Carey Brown wrote:After setting totalcoins to 500 you'll need to call
in order to update the display.
I don't see where you are setting totalcoins.
Carey Brown wrote: Steps:
1) set totalcoins to 500
2) set lblpoints text to new value of totalcoins
3) post your changes
L Ze wrote:I've a integer at the top to set totalcoins = 500
This code lblpoints.setText(String.valueOf(totalcoins)); is to set lblpoints text to new value of total coins?
All things are lawful, but not all things are profitable.
Knute Snortum wrote:
L Ze wrote:I've a integer at the top to set totalcoins = 500
But you need it again in the resetActionListener() method, or it won't be reset when you push the button.
This code lblpoints.setText(String.valueOf(totalcoins)); is to set lblpoints text to new value of total coins?
Not quite. It sets the text of lblpoints to the current value of totalcoins.
Do the exact same thing for ocoin.L Ze wrote:
Knute Snortum wrote:
L Ze wrote:I've a integer at the top to set totalcoins = 500
But you need it again in the resetActionListener() method, or it won't be reset when you push the button.
This code lblpoints.setText(String.valueOf(totalcoins)); is to set lblpoints text to new value of total coins?
Not quite. It sets the text of lblpoints to the current value of totalcoins.
I think I'm nearly there, I've placed this code lblpoints.setText(String.valueOf(totalcoins = 500)); in the Reset button and it does reset back to 500 when I click on the reset button however the ocoins label doesn't reset and when I click on the add button it will add onto the previous reset number
Carey Brown wrote:
Do the exact same thing for ocoin.L Ze wrote:
Knute Snortum wrote:
L Ze wrote:I've a integer at the top to set totalcoins = 500
But you need it again in the resetActionListener() method, or it won't be reset when you push the button.
This code lblpoints.setText(String.valueOf(totalcoins)); is to set lblpoints text to new value of total coins?
Not quite. It sets the text of lblpoints to the current value of totalcoins.
I think I'm nearly there, I've placed this code lblpoints.setText(String.valueOf(totalcoins = 500)); in the Reset button and it does reset back to 500 when I click on the reset button however the ocoins label doesn't reset and when I click on the add button it will add onto the previous reset number
Of course it won't, you're setting totalcoins=500 inside it. It might be clearer for you if you broke this into two lines.L Ze wrote:
Carey Brown wrote:
Do the exact same thing for ocoin.L Ze wrote:
Knute Snortum wrote:
L Ze wrote:I've a integer at the top to set totalcoins = 500
But you need it again in the resetActionListener() method, or it won't be reset when you push the button.
This code lblpoints.setText(String.valueOf(totalcoins)); is to set lblpoints text to new value of total coins?
Not quite. It sets the text of lblpoints to the current value of totalcoins.
I think I'm nearly there, I've placed this code lblpoints.setText(String.valueOf(totalcoins = 500)); in the Reset button and it does reset back to 500 when I click on the reset button however the ocoins label doesn't reset and when I click on the add button it will add onto the previous reset number
ocoins.setText(String.valueOf(totalcoins = 500)); only set ocoins value to 500 but doesn't reset it?