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

Chapter 15 - Programming question 5 \"Checkerboard\" Write a program that takes

ID: 3725392 • Letter: C

Question

Chapter 15 - Programming question 5 "Checkerboard"

Write a program that takes a positive integer n and displays an n x n checkerboard. For example, when n = 5, the program displays as in the image below. Make sure that adjacent squares differ in color regardless of whether n is odd or even. Write the program in such a way that it works for different values of n by changing only one line in your code. Hint: Use un-editable TextField objects in a GridPane, and use CSS to set background colors.

*Only use chapter materials for this program

*Use javaFX components for this program

Can someone please help me with this?

Exercise14_ 06

Explanation / Answer

package checkers;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Checkers extends Application {
  
    @Override
    public void start(Stage primaryStage) {

        GridPane grid = new GridPane();
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(10);
        grid.setVgap(10);
        grid.setPadding(new Insets(25, 25, 25, 25));
        Text introText = new Text("Welcome to Simple Checkers!");
        introText.setFont(Font.font("Tahoma", FontWeight.NORMAL, 28));
        grid.add(introText, 0, 0, 1, 1);
        grid.setHalignment(introText, HPos.CENTER);
        grid.setGridLinesVisible(true);
        HBox buttonhbox = new HBox();
        buttonhbox.setPadding(new Insets(15, 12, 15, 12));
        buttonhbox.setSpacing(10);
      
        Button newGameBtn = new Button("New Game");
        newGameBtn.setPrefWidth(150);
        Button aboutBtn = new Button("About");
        aboutBtn.setPrefWidth(150);
        Button quitBtn = new Button("Quit");
        quitBtn.setPrefWidth(150);
        buttonhbox.getChildren().addAll(newGameBtn, aboutBtn, quitBtn);
        buttonhbox.setAlignment(Pos.CENTER);
        grid.add(buttonhbox, 0, 1);
      
        Scene scene = new Scene(grid, 600, 200);
        primaryStage.setScene(scene);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote