I'm unable to click one button, then click another button to swap with the previously clicked button. Then make the first clicked button a blank button.
I can't think of how to do this. I just try with if statements like
If button = this{ //this should find the first button
if button = that{ //this should find the second button
that = this //this swaps the buttons
}
this = blank //and ends with making the first button
blank
}
this doesn't work because it goes straight passed the second if statement, and makes the first button blank without swapping anything.
not much code to go off of, this is just test code to figure out this single action
public class SimpleButtonSwapper extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) {
GridPane pane = new GridPane();
pane.setPadding(new Insets(50, 50, 50, 50)); //creates 50 pixel padding
pane.setVgap(2);
pane.setHgap(2);
Scene scene = new Scene(pane);
Canvas canvas = new Canvas(50, 400);
GraphicsContext graphics = canvas.getGraphicsContext2D();
pane.getChildren().add(canvas);
stage.setTitle("Chess");
Button[] buttons = new Button[6];
for (int i = 0; i < 6; i++) {
buttons[i] = new Button();
buttons[i].setText("banana " + i);
}
for (int i = 0; i < 6; i++) {
pane.add(buttons[i], i, 0);
}
for (int i = 0; i < 6; i++) {
buttons[i].setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
}
});
}
stage.setScene(scene);
stage.show();
}
}