Results 1 to 1 of 1
Thread: Randomize checkboxes
- 05-11-2011, 08:19 AM #1
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
Randomize checkboxes
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 many bingo bricks he wanna play (The bingo brick look like the following picture: ImageShack® - Online Photo and Video Hosting).
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.
Java Code:public class testGUI extends JPanel { CheckBoxListener myListener = null; JCheckBox box1_1; JCheckBox box1_X; JCheckBox box1_2; JCheckBox box2_1; JCheckBox box2_X; JCheckBox box2_2; public testGUI() { setSize(170, 350); myListener = new CheckBoxListener(); box1_1 = new JCheckBox(""); box1_1.addItemListener(myListener); box1_X = new JCheckBox(""); box1_X.addItemListener(myListener); box1_2 = new JCheckBox(""); box1_2.addItemListener(myListener); box2_1 = new JCheckBox(""); box2_1.addItemListener(myListener); box2_X = new JCheckBox(""); box2_X.addItemListener(myListener); box2_2 = new JCheckBox(""); box2_2.addItemListener(myListener); super.setBorder(new TitledBorder("1 X 2")); super.setLayout(new GridLayout(13, 3)); super.add(box1_1); super.add(box1_X); super.add(box1_2); super.add(box2_1); super.add(box2_X); super.add(box2_2); } class CheckBoxListener implements ItemListener { List<Integer> list = new LinkedList<Integer>(); @Override public void itemStateChanged(ItemEvent e) { Object source = e.getSource(); if (source == box1_1) { if (box1_1.isSelected()) { list.add(11); box1_X.setVisible(false); box1_2.setVisible(false); } else { list.remove(list.equals(11)); box1_X.setVisible(true); box1_2.setVisible(true); } } if (source == box1_X) { if (box1_X.isSelected()) { list.add(12); box1_1.setVisible(false); box1_2.setVisible(false); } else { list.remove(list.equals(12)); box1_1.setVisible(true); box1_2.setVisible(true); } } if (source == box1_2) { if (box1_2.isSelected()) { list.add(13); box1_X.setVisible(false); box1_1.setVisible(false); } else { list.remove(list.equals(13)); box1_X.setVisible(true); box1_1.setVisible(true); } } if (source == box2_1) { if (box2_1.isSelected()) { list.add(21); box2_X.setVisible(false); box2_2.setVisible(false); } else { list.remove(list.equals(21)); box2_X.setVisible(true); box2_2.setVisible(true); } } if (source == box2_X) { if (box2_X.isSelected()) { list.add(22); box2_1.setVisible(false); box2_2.setVisible(false); } else { list.remove(list.equals(22)); box2_1.setVisible(true); box2_2.setVisible(true); } } if (source == box2_2) { if (box2_2.isSelected()) { list.add(23); box2_X.setVisible(false); box2_1.setVisible(false); } else { list.remove(list.equals(23)); box2_X.setVisible(true); box2_1.setVisible(true); } } }
Similar Threads
-
Checkboxes and MS Access DB
By m_patten2 in forum AWT / SwingReplies: 2Last Post: 11-26-2010, 01:56 AM -
Java help...Checkboxes
By university123 in forum New To JavaReplies: 32Last Post: 10-25-2010, 12:39 PM -
ComboBox with CheckBoxes
By heba.farouk in forum AWT / SwingReplies: 14Last Post: 06-09-2010, 11:03 AM -
CheckBoxes and JTables
By lakshayghai in forum AWT / SwingReplies: 1Last Post: 03-16-2010, 08:01 PM -
Problem with checkboxes
By carl in forum Java AppletsReplies: 1Last Post: 08-06-2007, 08:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks