java - count button clicks -
java - count button clicks -
i want count number of times button clicked using gui.
i did code:
private void jbutton1actionperformed(java.awt.event.actionevent evt) { int clicked = 0; clicked++; system.out.println(clicked); }
but showing output "1", each time click button.
i want every time click button show me count.
ex: if click button 2 times should give me output of "2".
you resetting counter every time click, because have defined variable within action method. seek not doing that.
int clicked = 0; // move outside private void jbutton1actionperformed(java.awt.event.actionevent evt) { // int clicked = 0; -- resets 0 each time clicked++; system.out.println(clicked); }
java swing jbutton
Comments
Post a Comment