This commit is contained in:
Joshua Perry 2023-02-05 21:53:18 +00:00
parent de3bec19cc
commit 6ecdb309a1
1 changed files with 44 additions and 11 deletions

View File

@ -15,15 +15,32 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.scene.Scene; import javafx.scene.Scene;
/**
* Class that contains the main method and starts the GUI
* @author r0r5chach
*/
public class Manager extends Application { public class Manager extends Application {
/**
* Attribute that stores the GUI's scene
*/
private static Scene scene; private static Scene scene;
/**
* Attribute that stores the GUI's stage
*/
public static Stage stage; public static Stage stage;
/**
* Attribute that stores the program's competitors
*/
private static CompetitorList competitors; private static CompetitorList competitors;
/**
* Attribute that stores the currently active controller
*/
private static Controller controller; private static Controller controller;
/**
* Creates the GUI and competitor list, then sets the main View
* @param stage the stage to use for the GUI
* @throws IOException if the scene's FXML file cannot be found
*/
@Override @Override
public void start(Stage stage) throws IOException { public void start(Stage stage) throws IOException {
competitors = createList(); competitors = createList();
@ -33,7 +50,9 @@ public class Manager extends Application {
Manager.stage.setScene(scene); Manager.stage.setScene(scene);
Manager.stage.show(); Manager.stage.show();
} }
/**
* Stops the GUI and outputs a report file
*/
@Override @Override
public void stop() { public void stop() {
try { try {
@ -43,11 +62,20 @@ public class Manager extends Application {
createErrorLog(e, "src/main/resources/com/r0r5chach/log.txt"); createErrorLog(e, "src/main/resources/com/r0r5chach/log.txt");
} }
} }
/**
* Change the root for the scene
* @param fxml the view to be loaded
* @throws IOException if the view file cannot be found
*/
public static void setRoot(String fxml) throws IOException { public static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml)); scene.setRoot(loadFXML(fxml));
} }
/**
* Load an FXML file
* @param fxml the file to be loaded
* @return the root to change the scene to
* @throws IOException if the file cannot be found
*/
public static Parent loadFXML(String fxml) throws IOException { public static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Manager.class.getResource(fxml + ".fxml")); FXMLLoader fxmlLoader = new FXMLLoader(Manager.class.getResource(fxml + ".fxml"));
Parent root = fxmlLoader.load(); Parent root = fxmlLoader.load();
@ -74,15 +102,20 @@ public class Manager extends Application {
break; break;
} }
return root; return root;
} }
/**
* Launch the GUI
* @param args the arguments passed to the program
*/
public static void main(String[] args) { public static void main(String[] args) {
launch(); launch();
} }
/**
* Create the competitor list
* @return the competitor list
*/
private CompetitorList createList() { private CompetitorList createList() {
CompetitorList competitors = null; CompetitorList competitors = null;
File valorantPlayers = new File("src/main/resources/com/r0r5chach/valorantPlayers.txt"); File valorantPlayers = new File("src/main/resources/com/r0r5chach/valorantPlayers.txt");