Question: JAVA: Im new to GUI and have created this grid, but cant figure out how to add clickable buttons to all of the circles on

JAVA: Im new to GUI and have created this grid, but cant figure out how to add clickable buttons to all of the circles on the top row. Could someone show me how to do this? I dont need action listeners. Just clickable buttons for now. Thanks!

import javafx.application.Application; import static javafx.application.Application.launch; import javafx.scene.Scene; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.layout.GridPane; import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; import javafx.scene.shape.Shape; import javafx.stage.Stage;

public class Grid extends Application {

private static final int TILE_SIZE = 80; private static final int COLUMNS = 6; private static int ROWS = 7;

public static void main(String[] args) { //Stage stage = new Stage(); //start(stage); launch(args);

}

@Override public void start(Stage primaryStage) {

Shape shape = new Rectangle((COLUMNS + 2) * TILE_SIZE, (ROWS) * TILE_SIZE); for (int i = 0; i < ROWS; i++) { for (int i2 = 0; i2 < COLUMNS; i2++) { Circle circle = new Circle(TILE_SIZE / 2); circle.setCenterX(TILE_SIZE / 2); circle.setCenterY(TILE_SIZE / 2); circle.setTranslateX(i * (TILE_SIZE + 5) + TILE_SIZE / 4); circle.setTranslateY(i2 * (TILE_SIZE + 5) + TILE_SIZE / 4); shape = Shape.subtract(shape, circle); } } GridPane pane = new GridPane(); pane.setAlignment(Pos.CENTER); pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5)); // pixel buffer layout pane.setHgap(5.5); // pixel per blocks pane.setVgap(5.5);

pane.getChildren().addAll(shape);

Scene scene = new Scene(pane); primaryStage.setTitle("GridPane"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!