private JPanel createFoodTypeButtons(String[] array) { JPanel radioPanel = new JPanel(); typeOfFood = new ArrayList<JRadioButton>(); JRadioButton type0Radio = new JRadioButton(this.e.nonPerishableFood); JRadioButton type1Radio = new JRadioButton(this.e.perishableFood); typeOfFood.add(type0Radio); typeOfFood.add(type1Radio); type0Radio.setActionCommand(this.e.nonPerishableFood); type1Radio.setActionCommand(this.e.perishableFood); // Register a listener for the radio buttons. RadioListener myListener = new RadioListener(type0Radio, type1Radio, newCreatureButton, newJewelButton); type0Radio.addActionListener(myListener); type1Radio.addActionListener(myListener); // Group the radio buttons. group = new ButtonGroup(); group.add(type0Radio); group.add(type1Radio); model = new DefaultButtonModel(); group.setSelected(model, false); radioPanel.setLayout(new GridLayout(0, 1)); radioPanel.add(type0Radio); radioPanel.add(type1Radio); return radioPanel; }
public void showForCreation() { hiddenObstacle.setSelected(false); hiddenObstacle.setEnabled(false); for (JRadioButton tof : typeOfFood) { tof.setEnabled(true); } newCreatureButton.setEnabled(true); newJewelButton.setEnabled(true); group.setSelected(model, true); }
public void update() { newCreatureButton.setEnabled(false); newJewelButton.setEnabled(false); if (food != null) { for (JRadioButton tof : typeOfFood) { tof.setEnabled(false); } group.setSelected(model, false); hiddenObstacle.setEnabled(true); if (food.returnIfWasHidden()) { hiddenObstacle.setSelected(true); } else { hiddenObstacle.setSelected(false); } } }