java – My page won’t load or even open when I click on my button JavaFX

So I created a simple page with several buttons to press to open new windows in Java with JavaFX, the problem is, when I click on my button, my new page wont open or load. I put a sysout at the beginning of the method, and it triggers, so I actually enter the method, but it doesn’t do anything else.

GestionnaireController.java:

package fr.agglomistral.controller;

import fr.agglomistral.classedao.BusDAO;
import fr.agglomistral.classemetier.Bus;
import fr.agglomistral.outils.ConnexionMysql;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.stage.Window;

import java.io.IOException;
import java.sql.SQLException;

public class GestionnaireController {
    @FXML
    public Button manageBus;
    @FXML
    public Button manageLines;
    @FXML
    private Stage stage;
    @FXML
    private Scene scene;
    @FXML
    private Parent root;
    @FXML
    private Button submitButton;
    @FXML
    private TextField marqueField;
    @FXML
    private TextField immatriculationField;
    @FXML
    private TextField placesAssisesField;
    @FXML
    private TextField placesDeboutField;

    @FXML
    public void openGestionBus(ActionEvent actionEvent) {
        try {
            System.out.println("test");
            root = FXMLLoader.load(getClass().getResource("/fr/agglomistral/vues/gestionnaire/bus/GestionBus.fxml"));
            stage =(Stage)((Node)actionEvent.getSource()).getScene().getWindow();
            scene = new Scene(root,1200,700);
            Image favicon = new Image(getClass().getResourceAsStream("/fr/agglomistral/vues/LogoFini.png"));
            stage.getIcons().add(favicon);
            stage.setTitle("AggloMistral Gestion des Bus");
            stage.setScene(scene);
            stage.show();
        } catch (IOException e) {
        }
    }
}

So the functio I’m using is “openGestionBus”

And this is my fxml file:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="700.0" prefWidth="1200.0" style="-fx-background-color: white;" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.agglomistral.controller.GestionnaireController">
   <children>
      <VBox prefHeight="700.0" prefWidth="1200.0" style="-fx-background-color: a1e3e3;">
         <children>
            <ImageView fitHeight="135.0" fitWidth="172.0">
               <image>
                  <Image url="@../LogoFini.png" />
               </image>
               <VBox.margin>
                  <Insets left="530.0" />
               </VBox.margin>
            </ImageView>
            <Label text="Bienvenu ">
               <VBox.margin>
                  <Insets bottom="-37.0" left="547.0" top="23.0" />
               </VBox.margin>
               <font>
                  <Font size="33.0" />
               </font>
            </Label>
            <Button fx:id="manageBus" cache="true" mnemonicParsing="false" onAction="#openGestionBus" prefHeight="58.0" prefWidth="390.0" style="-fx-background-color: a1e3e3; -fx-border-color: #014d6d; -fx-border-radius: 5;" text="Gérer les Bus" textFill="#014d6d">
               <font>
                  <Font name="System Bold" size="23.0" />
               </font>
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <VBox.margin>
                  <Insets left="420.0" right="5.0" top="70.0" />
               </VBox.margin>
            </Button>
            <Button fx:id="manageLines" cache="true" mnemonicParsing="false" onAction="#openGestionLignes" prefHeight="59.0" prefWidth="390.0" style="-fx-background-color: a1e3e3; -fx-border-color: #014d6d; -fx-border-radius: 5;" text="Gérer les lignes" textFill="#014d6d">
               <font>
                  <Font name="System Bold" size="23.0" />
               </font>
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <VBox.margin>
                  <Insets left="420.0" right="5.0" top="10.0" />
               </VBox.margin>
            </Button>
            <Button fx:id="manageJourney" cache="true" mnemonicParsing="false" onAction="#openGestionParcours" prefHeight="63.0" prefWidth="390.0" style="-fx-background-color: a1e3e3; -fx-border-color: #014d6d; -fx-border-radius: 5;" text="Gérer les parcours" textFill="#014d6d">
               <font>
                  <Font name="System Bold" size="23.0" />
               </font>
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <VBox.margin>
                  <Insets left="420.0" right="5.0" top="10.0" />
               </VBox.margin>
            </Button>
            <Button fx:id="manageStations" cache="true" layoutX="15.0" layoutY="382.0" mnemonicParsing="false" onAction="#openGestionStations" prefHeight="63.0" prefWidth="390.0" style="-fx-background-color: a1e3e3; -fx-border-color: #014d6d; -fx-border-radius: 5;" text="Gérer les stations" textFill="#014d6d">
               <font>
                  <Font name="System Bold" size="23.0" />
               </font>
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <VBox.margin>
                  <Insets left="420.0" right="5.0" top="10.0" />
               </VBox.margin>
            </Button>
            <Button fx:id="logout" cache="true" mnemonicParsing="false" onAction="#logout" prefHeight="39.0" prefWidth="333.0" style="-fx-background-color: a1e3e3; -fx-border-color: #014d6d; -fx-border-radius: 50;" text="Se Déconnecter" textFill="#014d6d">
               <font>
                  <Font name="System Bold" size="27.0" />
               </font>
               <opaqueInsets>
                  <Insets />
               </opaqueInsets>
               <VBox.margin>
                  <Insets left="440.0" right="40.0" top="95.0" />
               </VBox.margin>
            </Button>
         </children>
      </VBox>
   </children>
</AnchorPane>

The button im pressing is the manageBus button And here is my project files:

Leave a Comment