import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class App extends Application { private static Scene scene; public static void main(String[] args) throws Exception { launch(args); } @Override public void start(Stage stage) throws IOException { scene = new Scene(loadFXML("mainScene")); stage.setScene(scene); stage.show(); } private static Parent loadFXML(String fileName) throws IOException { FXMLLoader loader = new FXMLLoader(App.class.getResource(fileName+".fxml")); return loader.load(); } static void setRoot(String fileName) { try { trySetRoot(fileName); }catch(IOException e) { System.err.println("Hiba! Az FXML betöltése sikertelen!"); System.err.println(e.getMessage()); } } static void trySetRoot(String fileName) throws IOException { scene.setRoot(loadFXML(fileName)); } }