I am trying to change the text of a Button in a GridPane when the Button is clicked. I have successfully managed to do so. but, I am getting this exception.
I have this function that changes the text.
public void clicker(Button b) {
if (b.getText().equals(" ")) {
if (turn == 0) {
b.setText("X");
b.setFont(Font.font("Times", FontWeight.EXTRA_BOLD,
60));
turn = 1;
} else if (turn == 1) {
Button bNew = new Button("Y");
bNew.setFont(Font.font("Times", FontWeight.EXTRA_BOLD, 60));
b.setText("Y");
b.setFont(Font.font("Times", FontWeight.EXTRA_BOLD,
60));
turn = 0;
}
}
}
this is the pane set up and event handler where the errors are happening.
GridPane pane = new GridPane();
b1.setMinSize(100, 100);
b2.setMinSize(100, 100);
b3.setMinSize(100, 100);
b4.setMinSize(100, 100);
b5.setMinSize(100, 100);
b6.setMinSize(100, 100);
b7.setMinSize(100, 100);
b8.setMinSize(100, 100);
b9.setMinSize(100, 100);
GridPane.setConstraints(b1, 0, 0);
GridPane.setConstraints(b2, 1, 0);
GridPane.setConstraints(b3, 2, 0);
GridPane.setConstraints(b4, 0, 1);
GridPane.setConstraints(b5, 1, 1);
GridPane.setConstraints(b6, 2, 1);
GridPane.setConstraints(b7, 0, 2);
GridPane.setConstraints(b8, 1, 2);
GridPane.setConstraints(b9, 2, 2);
pane.getChildren().addAll(b1, b2, b3, b4, b5, b6, b7, b8, b9);
b1.setOnAction((event) -> {
clicker(b1);
pane.getChildren().add(b1);
});
b2.setOnAction((event) -> {
clicker(b2);
pane.getChildren().add(b2);
});
any help would be appreciated. thanks