Example #1
0
  private void make_dice_and_JCheckBoxes(final DiceBoard db, boolean cheat) {
    diceSet.setBackground(Color.white);
    GridBagLayout gb = new GridBagLayout();
    GridBagConstraints gc;
    diceSet.setLayout(gb);
    for (int die = 0; die < DiceBoard.NUMDIE; die++) {
      dice[die] = new GuiDice(db.getDie(die), cheat);
      gc = new GridBagConstraints();
      gc.gridy = 0;
      gc.gridx = die;
      gb.setConstraints(dice[die], gc);
      diceSet.add(dice[die]);
    }
    // Add the roll JButton
    gc = new GridBagConstraints();
    gc.gridy = 0;
    gc.gridx = DiceBoard.NUMDIE;
    gc.gridwidth = GridBagConstraints.REMAINDER;
    gc.fill = GridBagConstraints.HORIZONTAL;
    gc.weightx = 1.0;
    gb.setConstraints(rollButton, gc);
    diceSet.add(rollButton);

    for (int die = 0; die < DiceBoard.NUMDIE; die++) {
      final int which = die;
      chbs[which] = new JCheckBox();
      chbs[which].setEnabled(false);
      chbs[which].addItemListener(
          new ItemListener() {
            // This method is called when the user clicks the JCheckBox
            public void itemStateChanged(ItemEvent e) {
              if (e.getStateChange() == ItemEvent.DESELECTED) db.getDie(which).setLock(false);
              else db.getDie(which).setLock(true);
            }
          });
      gc = new GridBagConstraints();
      gc.gridy = 1;
      gc.gridx = die;
      gb.setConstraints(chbs[die], gc);
      diceSet.add(chbs[which]);
    }

    gc = new GridBagConstraints();
    gc.gridy = 1;
    gc.gridx = DiceBoard.NUMDIE;
    gc.gridwidth = GridBagConstraints.REMAINDER;
    gb.setConstraints(nextPlayerJButton, gc);
    diceSet.add(nextPlayerJButton);
  }
Example #2
0
 /* The following methods are concerned with controlling the game state */
 public void configure_die(DiceBoard db) {
   for (int die = 0; die < DiceBoard.NUMDIE; die++) {
     dice[die].showval(db.getDie(die).getValue());
   }
 }