Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help on the GUIDriver(how should I write everything in the method se

ID: 3731584 • Letter: I

Question

I need some help on the GUIDriver(how should I write everything in the method section) and on how to make everything an aggregate of that GUIDriver

javafx.scene.Scene javafx.stage.Stage javaf.application.Application javafx.scene.image lmage see JavaFX API aFX API> ee JavaFX API javafx.scene.layout.Flowpane esee JavaFXAPl GUIDriver PairOfDice x.scene.control.Button Die ie2View ImageView +getDie1Image(void) Image +getDie2lmage(void): Image ssee JavaFX API start primaryStage Stage) :void processButtonPress(event: ActionEvent void main (args: String) void(optional depending on IDE) +getDielmage(void Image javafx.event.ActionEvent Dice Image Files vaFXAPI gDice javafx.scene.text.Text; javafx.scene.image.lmageVie oid) int structor avaFX API> JavaFXAPI tro +toStringvoid): String

Explanation / Answer

representation of code :-

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

public class PigWithGraphicsPanel extends JPanel

{

private JPanel panel; // main panel//

private JButton roll; //allows the players to roll his dice//

private JButton hold; // allows the player to hold his dice and give up his turn//

private JButton computersTurn; // allows the player to activate the computers turn//

public static JLabel playersPointsDisplay; // label that tells you how many points you rolled, how many points you have scored in your turn, and your total points//

public static JLabel computersPointsDisplay; // Does the same thing as the players points display except for the computers points.

final static int WinningScore= 100; // the game is played to 100 points//

static int playersPointsPerRoll; // the dice added together//

static int playersPointsPerRound; // the total points you have scored so far in your turn//

static int playersPoints; // your total points//

static int computersPointsPerRoll; // the computers dice added together//

public static int computersPointsPerRound; // the computers points so far in its turn//

public static int computersPoints; // the total points of the computers//

public PigWithGraphicsPanel()

{

roll = new JButton("Roll");

roll.setEnabled(true);

hold = new JButton ("Hold");

hold.setEnabled(true);

computersTurn = new JButton ("Switch");

computersTurn.setEnabled(false);

playersPointsDisplay = new JLabel("You scored " + playersPointsPerRoll+ " this roll. Your points per round are " + playersPointsPerRound +"Your final score is " + playersPoints);

computersPointsDisplay = new JLabel ("The computer scored " + computersPointsPerRoll + " with this roll. The computers total score this round is " + computersPointsPerRound + "The computers total points are " + computersPoints);

ButtonListener listener = new ButtonListener();

ComputerListener compLis = new ComputerListener();

roll.addActionListener(listener);

hold.addActionListener(listener);

computersTurn.addActionListener(compLis);

panel = new JPanel();

panel.setPreferredSize(new Dimension(200,400));

panel.setBackground(Color.blue);

add(playersPointsDisplay);

add(roll);

add(hold);

add(computersTurn);

add(computersPointsDisplay);

}

private class ButtonListener implements ActionListener

{

public void actionPerformed (ActionEvent event)

{

PairOfDice playersDice = new PairOfDice();// creates a new pair of dice for the player//

playersDice.roll();

int playersRoll1= playersDice.getValue1();//gets the value of the first dice//

int playersRoll2= playersDice.getValue2();// gets the value of the second dice//

if (event.getSource() == roll)

{

if (playersPoints >= WinningScore) // checks to see if you have won//

{

playersPointsDisplay.setText("You won!");

roll.setEnabled(false);

hold.setEnabled(false);

computersTurn.setEnabled(false);

}

if (computersPoints >= WinningScore) // checks to see if you have lost//

{

playersPointsDisplay.setText("You Lost");

roll.setEnabled(false);

hold.setEnabled(false);

computersTurn.setEnabled(false);

}

if (playersRoll1 ==1 || playersRoll2==1) // if you roll a one you points so far in the round are lost and it becomes the computers turn//

{

playersPointsDisplay.setText("You rolled a 1 you have lost your points this round");

playersPointsPerRound = 0;

playersPointsPerRoll = 0;

roll.setEnabled(false);

computersTurn.setEnabled(true);

hold.setEnabled(false);

}

else

{

playersPointsPerRoll = playersRoll1 + playersRoll2;

playersPointsPerRound += playersPointsPerRoll;

playersPointsDisplay.setText("You scored " + playersPointsPerRoll+ " this roll. Your points per round are " + playersPointsPerRound +"Your final score is " + playersPoints);

// ^ rewrites the players points display to show the current points per round//

}

}

if (event.getSource()== hold) // if you hit hold it will add your points per your turn to your total points and your turn will be over//

{

playersPoints += playersPointsPerRound;

computersTurn.setEnabled(true);

roll.setEnabled(false);

playersPointsPerRound = 0;

playersPointsPerRoll = 0;

playersPointsDisplay.setText("You scored " + playersPointsPerRoll+ " this roll");

hold.setEnabled(false);

}

}

}

private class ComputerListener implements ActionListener

{

public void actionPerformed (ActionEvent event)

{

PairOfDice playersDice = new PairOfDice();// creates a new pair of dice for the player//

playersDice.roll();

int computersRoll1= playersDice.getValue1();//gets the value of the first dice//

int computersRoll2= playersDice.getValue2();// gets the value of the second dice//

if (playersPoints >= WinningScore) // checks to see if the players won//

{

playersPointsDisplay.setText("You won!");

roll.setEnabled(false);

hold.setEnabled(false);

computersTurn.setEnabled(false);

}

if (computersPoints >= WinningScore) // checks to see if the computer won//

{

playersPointsDisplay.setText("You Lost");

roll.setEnabled(false);

hold.setEnabled(false);

computersTurn.setEnabled(false);

}

if (computersPointsPerRound >= 20) // if the computer scores more than 20 points it will end the computers turn so that the players has a chance to win//

{

computersPointsPerRound =20;

computersPoints += computersPointsPerRound;

computersPointsDisplay = new JLabel ("The computer scored " + computersPointsPerRoll + " with this roll");

computersTurn.setEnabled(false);

roll.setEnabled(true);

hold.setEnabled(true);

}

if (computersRoll1 == 1 || computersRoll2 ==1) // if the computer rolls a one the computer looses its points in the round and it becomes the players turn//

{

computersPointsDisplay.setText("The computer rolled a one its has lost its points this round its total is " + computersPoints);

computersPointsPerRoll = 0;

computersPointsPerRound = 0;

roll.setEnabled(true);

hold.setEnabled(true);

computersTurn.setEnabled(false);

}

else

{

computersPointsPerRoll = computersRoll1 + computersRoll2 ;

computersPointsPerRound += computersRoll1 + computersRoll2;

computersPoints += computersPointsPerRound;

computersPointsDisplay.setText ("The computer scored " + computersPointsPerRoll + " with this roll. The computers total score this round is " + computersPointsPerRound + "The computers total points are " + computersPoints);

roll.setEnabled(false);

hold.setEnabled(false);

computersTurn.setEnabled(true);

}

}

}

}