/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */ package javafx_calebfontenot; import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; /** * * @author caleb */ public class Checkerboard extends Application { @Override public void start(Stage primaryStage) throws Exception { Pane pane = new Pane(); // Create a pane object Scene scene = new Scene(pane, 800, 800); // Create a scene object primaryStage.setScene(scene); // Set the stage scene to the scene object primaryStage.show(); // Make the window display on the screen Rectangle[][] r = new Rectangle[8][8]; //Fill array with rectangle objects. for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { r[i][j] = new Rectangle(); } } int j = 0; for (int i = 0; i < 8; ++i) { for (j = 0; j < 8; ++j) { r[i][j].setWidth(80); r[i][j].setHeight(80); if (j > 0) { r[i][j].setX(r[i][j - 1].getX() + 75); } if ((i + j) % 2 == 0) { r[i][j].setFill(Color.RED); } else { r[i][j].setFill(Color.BLACK); } r[i][j].setY((i + 1) * 75); pane.getChildren().add(r[i][j]); } } } public static void main(String[] args) { launch(args); } }