• Post Reply Bookmark Topic Watch Topic
  • New Topic

Randomize checked checkboxes?  RSS feed

 
Tobias Tangfelt
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with my checkboxes.
The program I am creating are going to show a sort of a bingo game. The user start to choose hove man bingo bricks he wanna play (The bingo brick look like the following picture: Picture).
The user should have the ability to enter the checkboxes by here self or the user could randomize all the bricks checkboxes. If the user has marked one check box in one of the bricks and then wan´t to randomize the rest of them then the checkbox that the user has marked shall be marked, and all the others should randomize.
My question is hove I could make such randomize with just checkboxes?

In my code example I only show you six different checkboxes, as you can see in the picture it is a lot of more of them. But I am using exactly the same code for every checkboxes in the program. It´s just to hold down the amount of code. This is all the code I use in the class but for my program I have duplicate it some more times.


 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you adding super. before your add() invocations?
What a dreadful non-object-oriented way to do it, using one actionPerformed method and if source ==. You need to create a class which implements the ActionListener interface, or use an AbstractAction. Rob posted an example of an AbstractAction here. You can link to a BingoGame class and pass the numbers back and forth as method arguments.

myCheckBox.setSelected(Math.random() >= 0.75); ??
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And just to confirm how dreadfully error-prone that one method approach is: I think you have an error for no 2_2.
 
Tobias Tangfelt
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your tips. The problem solved!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!