Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, i am trying to align 2 gridpanes beside eachother using javaFX. i have written the code, but when i run it only one board

Hi, i am trying to align 2 gridpanes beside eachother using javaFX. i have written the code, but when i run it only one board shows. Could you please look at my code and help me figure out where im going wrong. thank you.

This is the code:

import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.control.Label; import javafx.scene.control.Button; import javafx.event.*; import javafx.scene.input.*; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.layout.HBox; public class BattleShipBoardGUI extends Application { private Stage primary; private Scene scene; private Scene scene2; private GridPane root; private Button [][] gridButtons = new Button[10][10];

public static void main(String[] args){ launch(args);

} @Override public void start (Stage primaryStage) throws Exception{ GridPane grid = new GridPane(); //GridPane grid2 = new GridPane(); for(int row = 0; row < 10 ; row++){ for(int column = 0; column <10; column ++){ Button b = new Button(""); gridButtons[row][column] = b; gridButtons[row][column].setPrefSize(30, 30); grid.add(gridButtons[row][column] , row , column); } } GridPane grid2 = new GridPane(); for (int row = 0 ; row <10 ; row++){ for(int column = 0; column <10; column ++){ Button b2 = new Button(""); gridButtons[row][column] = b2; gridButtons[row][column].setPrefSize(80,80); grid2.add(gridButtons[row][column] , row, column); } } HBox hbox = new HBox(); hbox.setSpacing(10); hbox.getChildren().addAll( grid, grid2);

BorderPane root = new BorderPane(); BorderPane root2 = new BorderPane(); root.setCenter(grid); root2.setRight(grid2); Scene scene = new Scene(root,300, 300); Scene scene2 = new Scene(root2 , 200 , 200);

primaryStage.setTitle("BattleShip"); primaryStage.setScene(scene); primaryStage.setScene(scene2); primaryStage.show();

}

}

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

Students also viewed these Databases questions