Reputation: 1
I am working on a simple cart application as my first functional project with Java. The application will track which carts are checked out and which ones are available at each building for the first iteration.
I used an if else function to build the GridPane bldg1Grid. The pane only includes the buttons to check out a cart if it meets the criteria of having a true status for in stock as well as a matching building number for that GridPane. The if else function works the first time and depending on the carts original status, shows or does not show that carts button. However after a cart is checked out it uses a method to changed that status to false. The GridPane seems stuck on the original one built but I confirmed using a System.out.println statement of the in stock variable and it returns the change correctly. I am VERY new to JavaFX but I have tried making the else statement use /// bldg1Grid.getChildren().clear() /// and removeAll functions and neither has seemed to work. I also tried making a clear the GridPane function to force it to start over but could not utilize the GridPane in its own function for some reason. Help?
Cart code:
Cart cart1 = new Cart(1,1,true,true,true);
Cart cart2 = new Cart(2,1,true,true,true);
Cart cart3 = new Cart(3,2,true,true,true);
This is one of the original scenes buttons that switches to building 1 where the problem is:
@Override public void start(Stage primaryStage){
stage = primaryStage;
cart1Status = this.cart1Status;
//Main scene build
mainHeader = new Label();
mainHeader.setText("Select which building cart is at:");
bldg1 = new Button();
bldg1.setText("Building 1");
bldg1.setOnAction(event -> bldg1Select());
My gridpane buildout: - this iteration I tried making it add an alternate button for the else and also tried taking the this.status and making it a new variable to try and utilize it that way:
GridPane bldg1Grid = new GridPane();
bldg1Grid.addRow(0, buildingLabel);
if (cart1Status == true){
bldg1Grid.addRow(1, btnC1);
} else if (cart1Status == false){
bldg1Grid.addRow(0, btnTest);
}
else{
}
if (cart2.status == true && cart1.bldgNmbr == 1){
bldg1Grid.addRow(2, btnC2);
} else {}
if (cart3.status == true && cart1.bldgNmbr == 1){
bldg1Grid.addRow(3, btnC3);
} else {}
my method to attempt to clear the gridpane:
private void clearBldg1Grid(){
bldg1Grid.getChildren().clear();
}
There are no error messages and the variable does appear to change and stay changed after using the method to change the status from true to false. I proved this using println statements and had them print before and after getting to the page when I switched back and forth from the main scene. The expected output is each time you go to building 1 it shows only carts that status == true && bldgNmbr == 1.
Upvotes: 0
Views: 124
Reputation: 1
I failed to set the variable properly at the start of my code with ''' Private GridPane bldg1Grid; ''' Once I did that I was able to call it in my method that cleared the nodes based on an if function.
Upvotes: 0