Skip to content

Commit

Permalink
Feat: Own class for loading scene for better code
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 13, 2026
1 parent 6afdd4e commit 5adb369
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ntnu.systemutvikling.team6.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import ntnu.systemutvikling.team6.HmHApplication;
import ntnu.systemutvikling.team6.models.Charity;

import java.io.IOException;

public class LoaderScene {
public static void LoadScene(String sceneName, ActionEvent event, Charity charity){
try {
System.out.println(HmHApplication.class.getResource("/fxml/"+ sceneName +".fxml"));
FXMLLoader fxmlLoader =
new FXMLLoader(HmHApplication.class.getResource("/fxml/"+ sceneName +".fxml"));
Parent root = fxmlLoader.load();

System.out.println("Controller: " + fxmlLoader.getController());
DonationPageController controller = fxmlLoader.getController();
controller.setCharity(charity);

Stage stage = (Stage) ((Node)event.getSource()).getScene().getWindow();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setFullScreen(true);
stage.show();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 5adb369

Please sign in to comment.