Uri D. Charles
Uri D. Charles

Reputation: 57

How can I make this program display a counter a different way?

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

Answers (1)

Masudul
Masudul

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

Related Questions