Skip to content
Snippets Groups Projects
SceneController.java 3.34 KiB
package no.ntnu.idatt1002.demo.controller;

import java.io.IOException;

import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class SceneController {

  private Stage stage;
  private Scene scene;

  public void switchStartMenu(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/FirstMenu.fxml"));
    Parent root = loader.load();
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }
  public void switchNewBudget(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/NewBudget.fxml"));
    Parent root = loader.load();
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }

  public void switchIncome(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/Income.fxml"));
    Parent root = loader.load();
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }

  public void switchExpenses(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/Expenses.fxml"));
    Parent root = loader.load();
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }

  public void switchOverview(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/Overview.fxml"));
    Parent root = loader.load();
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }

  public void switchMainMenu(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/MainMenu.fxml"));
    Parent root = loader.load();
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
  }
  public void addIncome(ActionEvent event) throws IOException {
    FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/addIncome.fxml"));
    Scene newScene = new Scene(loader.load());
    Stage newStage = new Stage();
    newStage.setScene(newScene);
    newStage.setResizable(false);
    newStage.initModality(Modality.APPLICATION_MODAL);

    newStage.show();
  }

  public void underProgress(ActionEvent event) throws IOException{
    FXMLLoader loader = new FXMLLoader(SceneController.class.getResource("/view/underProgress.fxml"));
    Scene newScene = new Scene(loader.load());
    Stage newStage = new Stage();
    newStage.setScene(newScene);
    newStage.setResizable(false);
    newStage.initModality(Modality.APPLICATION_MODAL);

    newStage.show();
  }
  public void closeButton(ActionEvent actionEvent) {
    final Node source = (Node) actionEvent.getSource();
    final Stage stage = (Stage) source.getScene().getWindow();
    stage.close();
  }
}