This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Code inside JButton  RSS feed

 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having trouble writing simple code inside a JButton. When I click a JButton "set", i need to have error checking done. A text box called player_number_text holds and stores a number in an array. If the number is already used, it reports an error, does not store and allows the user to enter again. If the number isn't used, it stores it.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just a suggestion.

rather than have player_number_text, and all the associated error checking for
digit length, non digits etc, have you considered using a JSpinner, with a
range matching your player numbers. Then, on clicking 'set', you'd only have
to check previous use of the spinner's value.

you could even code it so the spinner only has player numbers not previously 'set',
but this would depend on whether you want to use the spinner's normal range
of player numbers elsewhere in your program.
 
John Lockheart
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There might have been an error. In your reply there is nothing written.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!