Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions