Reputation: 57
So I understand how to make it so when a user presses a button, the count goes up, but how would I make it so it displays the amount of times the button has been pressed in a different way. For example, if the user pressed the button 3 times, it would say 123, instead of 3.
This is my current method with does it a conventional way,
public void actionPerformed(ActionEvent event) {
count++;
label.setText("Pushes: " + count);
}
So I'm thinking maybe I can make it so it loops through each posted value and displays that?
Upvotes: 0
Views: 163
Reputation: 21971
Initialise countStr
globally, than on the button click append the count with StringBuilder
like:
StringBuilder countStr= new StringBuilder();
public void actionPerformed(ActionEvent event) {
count++
countStr.append(count);
label.setText("Pushes: " +countStr);
}
Upvotes: 4