public class DiceDisplay extends JPanel { private static final long serialVersionUID = 2251148005824463126L; /** * create the display panel * @param rollAction the action to take if the roll button is pressed * @param rerollAction the action to take if the re-roll button is pressed */ public DiceDisplay(ActionListener rollAction,ActionListener rerollAction) { super(new BorderLayout(),true); _selects = new JCheckBox[5]; _dice = new DieDisplay[5]; // TODO -- create the layout for the dice panel // in doing so, the code must create the 5 DieDisplay objects and the 5 check boxes // and put them into two arrays (_selects for the check boxes and _dice for the Die displays) // it must also create the two button (Roll and ReRoll), put them into _roll and _reroll fields // and attach the actionlisteners that were passed in to the corresponding buttons } /** * setup the UI to be ready to roll */ public void enableRoll() { _roll.setEnabled(true); _reroll.setEnabled(false);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

This code is all in Java 

 

Need help with the parts that say TODO

-------------------------------------------------------

 

//DiceDisplay.java
package edu.vtc.cis2271.yahtzee;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

//DiceDisplay - display the five dice for a single turn of yahtzee

public class DiceDisplay extends JPanel
{
private static final long serialVersionUID = 2251148005824463126L;

/**
* create the display panel
* @param rollAction the action to take if the roll button is pressed
* @param rerollAction the action to take if the re-roll button is pressed
*/
public DiceDisplay(ActionListener rollAction,ActionListener rerollAction)
{
super(new BorderLayout(),true);
_selects = new JCheckBox[5];
_dice = new DieDisplay[5];

// TODO -- create the layout for the dice panel
// in doing so, the code must create the 5 DieDisplay objects and the 5 check boxes
// and put them into two arrays (_selects for the check boxes and _dice for the Die displays)
// it must also create the two button (Roll and ReRoll), put them into _roll and _reroll fields
// and attach the actionlisteners that were passed in to the corresponding buttons
}

/**
* setup the UI to be ready to roll
*/
public void enableRoll()
{
_roll.setEnabled(true);
_reroll.setEnabled(false);
}

/**
* tell the dice display to set the values
* @param dice the 5 dice that should be displayed in the roll
*/
public void setRoll(int dice[])
{
for (int i = 0; i < 5; i++)
{
_dice[i].rollToValue(1000,dice[i]);
_selects[i].setSelected(false);
_selects[i].setEnabled(true);
}
}

/**
* set up the UI to be ready for the user to request re-rolling selected dice
*/
public void enableReRoll()
{
_roll.setEnabled(false);
_reroll.setEnabled(true);
}

/**
* update the dice the user requested to be re-rolled
* @param dice the complete array of 5 dice values
* @param allowSelects if true, allow the dice to be selected for another roll
*/
public void setReRoll(int dice[],boolean allowSelects)
{
for (int i = 0; i < 5; i++)
{
if (!_selects[i].isSelected())
{
_dice[i].rollToValue(1000,dice[i]);
_selects[i].setSelected(false);
}
_selects[i].setEnabled(allowSelects);
}
}

/**
* turn off the ability to re-roll
*/
public void disableReRoll()
{
_reroll.setEnabled(false);
}

/**
* get the current state of the selections for which dice to keep
* @return the array of 5 booleans, each true means the corresponding die should be kept (not re-rolled)
*/
public boolean[] getSelected()
{
boolean selected[] = new boolean[5];
for (int i = 0; i < 5; i++)
selected[i] = _selects[i].isSelected();
return selected;
}

private JCheckBox[] _selects; // the checkboxes indicating which dice to keep
private DieDisplay[] _dice; // the dice controllers themselves
private JButton _roll; // the roll button
private JButton _reroll; // the re-roll button
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
JQuery and Javascript
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education