Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gui;
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.stage.Stage;
- import model.Yatzy;
- public class MainApp extends Application {
- public static void main(String[] args) {
- Application.launch(args);
- }
- @Override
- public void start(Stage stage) {
- stage.setTitle("Yatzy");
- GridPane pane = new GridPane();
- this.initContent(pane);
- Scene scene = new Scene(pane);
- stage.setScene(scene);
- stage.setResizable(false);
- stage.show();
- }
- // -------------------------------------------------------------------------
- // Shows the face values of the 5 dice.
- private TextField[] txfValues;
- // Shows the hold status of the 5 dice.
- private CheckBox[] chbHolds;
- // Shows the results previously selected .
- // For free results (results not set yet), the results
- // corresponding to the actual face values of the 5 dice are shown.
- private TextField[] txfResults;
- // Shows points in sums, bonus and total.
- private TextField txfSumSame, txfBonus, txfSumOther, txfTotal;
- // Shows the number of times the dice has been rolled.
- private Label lblRolled;
- private Button btnRoll;
- private void initContent(GridPane pane) {
- pane.setGridLinesVisible(false);
- pane.setPadding(new Insets(10));
- pane.setHgap(10);
- pane.setVgap(10);
- // ---------------------------------------------------------------------
- GridPane dicePane = new GridPane();
- pane.add(dicePane, 0, 0, 40, 20);
- dicePane.setGridLinesVisible(false);
- dicePane.setPadding(new Insets(10));
- dicePane.setHgap(10);
- dicePane.setVgap(10);
- dicePane.setStyle("-fx-border-color: black");
- // initialize txfValues, chbHolds, btnRoll and lblRolled
- // TODO
- // ---------------------------------------------------------------------
- GridPane scorePane = new GridPane();
- pane.add(scorePane, 0, 20, 40, 32);
- scorePane.setGridLinesVisible(false);
- scorePane.setPadding(new Insets(10));
- scorePane.setVgap(5);
- scorePane.setHgap(10);
- scorePane.setStyle("-fx-border-color: black");
- int w = 100; // width of the text fields
- // Initialize labels for results, txfResults,
- // labels and text fields for sums, bonus and total.
- // TODO
- txfValues = new TextField[5];
- for (int i = 0; i < txfValues.length; i++) {
- txfValues[i] = new TextField();
- dicePane.add(txfValues[i], i, 0, 1, 1);
- txfValues[i].setPrefHeight(100);
- txfValues[i].setPrefWidth(100);
- txfValues[i].setEditable(false);
- }
- chbHolds = new CheckBox[5];
- for (int i = 0; i < chbHolds.length; i++) {
- chbHolds[i] = new CheckBox("Hold");
- dicePane.add(chbHolds[i], i, 0, 1, 15);
- }
- txfResults = new TextField[15];
- for (int i = 0; i < txfResults.length; i++) {
- txfResults[i] = new TextField();
- scorePane.add(txfResults[i], 10, i, 10, 1);
- txfResults[i].setPrefWidth(w);
- txfResults[i].setEditable(false);
- }
- Label[] lblResult = new Label[49];
- for (int i = 0; i < 6; i++) {
- lblResult[i] = new Label("" + (i + 1) + "-s");
- }
- lblResult[1] = new Label("Rolled:");
- pane.add(lblResult[1], 35, 18);
- lblResult[2] = new Label("1's:");
- pane.add(lblResult[2], 1, 21);
- lblResult[3] = new Label("2's:");
- pane.add(lblResult[3], 1, 23);
- lblResult[4] = new Label("3's:");
- pane.add(lblResult[4], 1, 25);
- lblResult[5] = new Label("4's:");
- pane.add(lblResult[5], 1, 27);
- lblResult[6] = new Label("5's:");
- pane.add(lblResult[6], 1, 29);
- lblResult[7] = new Label("6's:");
- pane.add(lblResult[7], 1, 31);
- // lblResult[8] = new Label("Sum:");
- // pane.add(lblResult[8], 10, 31);
- //
- // lblResult[9] = new Label("Bonus:");
- // pane.add(lblResult[9], 20, 31);
- lblResult[8] = new Label("One Pair:");
- pane.add(lblResult[8], 1, 33);
- lblResult[9] = new Label("Two Pair:");
- pane.add(lblResult[9], 1, 35);
- lblResult[10] = new Label("Three Same:");
- pane.add(lblResult[10], 1, 37);
- lblResult[11] = new Label("Four Same:");
- pane.add(lblResult[11], 1, 39);
- lblResult[12] = new Label("Full House:");
- pane.add(lblResult[12], 1, 41);
- lblResult[13] = new Label("Small Straight:");
- pane.add(lblResult[13], 1, 43);
- lblResult[14] = new Label("Large Straight:");
- pane.add(lblResult[14], 1, 45);
- lblResult[15] = new Label("Chance:");
- pane.add(lblResult[15], 1, 47);
- lblResult[16] = new Label("Yatzy:");
- pane.add(lblResult[16], 1, 49);
- // lblResult[19] = new Label("Sum:");
- // pane.add(lblResult[19], 10, 49);
- //
- // lblResult[20] = new Label("Total:");
- // pane.add(lblResult[20], 20, 49);
- }
- // -------------------------------------------------------------------------
- private Yatzy dice = new Yatzy();
- // Create a method for btnRoll's action.
- // Hint: Create small helper methods to be used in the action method.
- // TODO
- // -------------------------------------------------------------------------
- // Create a method for mouse click on one of the text fields in txfResults.
- // Hint: Create small helper methods to be used in the mouse click method.
- // TODO
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement