0

Hi I have 3 classes : Main, GuiController, AddcompetitionController

2 Views : Gui and another popupWindow : AddCompetition

I am trying to use GuiController inside AddcompetitionController. And I am having troubles. Can some1 help me please ?

AddcompetitionController - I am already trying to initialize GuiController gc and use its function (gc.refreshAll());

public class AddcompetitionController implements Initializable {

    private GuiController gc = new GuiController();           ------ initialize
    
    public void setGC(GuiController gc) {
        this.gc = gc ;
    }

    @FXML // dd/MM/yyyy
    void addCompetitionButtonAction(ActionEvent event) {
        String text = dateTF.getText();
        java.time.format.DateTimeFormatter formatter = java.time.format.DateTimeFormatter.ofPattern("dd/MM/yyyy");
        java.time.LocalDate textFieldAsDate = java.time.LocalDate.parse(text, formatter);
        java.sql.Date sqlDate = java.sql.Date.valueOf(textFieldAsDate);
        
        App.addCompetition(disciplineTF.getText(), categoryTF.getText(), sqlDate,
                cityTF.getText(), countryTF.getText());
        Stage stage = (Stage) button.getScene().getWindow();
        stage.close();
        gc.refreshAll();                                     ----- calling a method
    }
}

GuiController

public class GuiController implements Initializable {
 code ... initialize... etc

    @FXML
    void addCompetitionButtonAction(ActionEvent event) {
        Parent root;
            try {
                Stage stage = new Stage();
                root = FXMLLoader.load(getClass().getResource("/javaFX/AddCompetition.fxml"));
                Scene scene = new Scene(root);
                stage.setTitle("Add new competition");
                stage.setScene(scene);
                stage.show();                               
            } catch (IOException e) {
                e.printStackTrace();
            }   
    }

Main

package javaFX;

imports...

public class Main extends Application {
    
    public static void main(String[] args) {
        launch(args);
    }
    
    @Override
    public void start(Stage primaryStage)  {
        Parent root;
            try {
                root = FXMLLoader.load(getClass().getResource("/javaFX/Gui.fxml"));
                Scene scene = new Scene(root);
                primaryStage.setScene(scene);
                primaryStage.show();                                
            } catch (IOException e) {
                e.printStackTrace();
            }                       
    }
}
Simonsoft177
  • 175
  • 2
  • 22
  • 1
    Generally it's a bad idea to have one controller reference another: consider using a [MVC approach](https://stackoverflow.com/questions/32342864/applying-mvc-with-javafx/32343342#32343342) instead. However, you can pass the current `GuiController` instance to the `setGC()` method you defined using https://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml – James_D Jul 08 '20 at 17:51
  • Bro I just got the best grade for this project I dont care anymore NEVER AGAIN HIBERNATE!! I was suffering so much. Thanks for help anyway ! :)))) – Simonsoft177 Jul 08 '20 at 17:59

0 Answers0