Skip to content

Instantly share code, notes, and snippets.

@stoffie
Created July 28, 2014 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoffie/ef66987b402fc2760f14 to your computer and use it in GitHub Desktop.
Save stoffie/ef66987b402fc2760f14 to your computer and use it in GitHub Desktop.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxapplication7;
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.NumberBinding;
import javafx.geometry.HPos;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
/**
*
* @author Gabriele
*/
public class JavaFXApplication7 extends Application {
@Override
public void start(Stage stage) {
int w = 600;
int h = 600;
int size = 8;
GridPane board = new GridPane();
Scene scene = new Scene(board, w, h);
NumberBinding rectsAreaSize = Bindings.min(board.heightProperty(), board.widthProperty());
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; ++j) {
Rectangle rect;
if ((i + j) % 2 == 1) {
rect = new Rectangle(15.0, 15.0, Color.WHITE);
} else {
rect = new Rectangle(15.0, 15.0, Color.BLACK);
}
rect.widthProperty().bind(rectsAreaSize.divide(size));
rect.heightProperty().bind(rectsAreaSize.divide(size));
board.add(rect, i, j);
GridPane.setHalignment(rect, HPos.CENTER);
}
}
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment