Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. package javafx;
  3.  
  4.  
  5. import java.io.IOException;
  6. import java.util.Hashtable;
  7. import javafx.fxml.FXMLLoader;
  8. import javafx.scene.Parent;
  9. import javafx.scene.Scene;
  10. import javafx.stage.Stage;
  11.  
  12.  
  13. public class SceneManager {
  14. private static Stage stage;
  15. private static Hashtable<String, String> view = new Hashtable<>();
  16.  
  17. public static void addScene(String name, String path) throws IOException{
  18. view.put(name, path);
  19. }
  20.  
  21. public static void removeScene(String name){
  22. view.remove(name);
  23. }
  24.  
  25. public static void renderScene(String name){
  26. String path="";
  27. try{
  28. path = view.get(name);
  29. Parent root = FXMLLoader.load(SceneManager.class.getResource(path));
  30. Scene scene = new Scene(root);
  31. stage.setScene(scene);
  32. stage.show();
  33. } catch (IOException ex){
  34. System.err.println("Nie można załadować pliku XML z widokiem: "+path);
  35. } catch (RuntimeException ex){
  36. System.err.println("Nazwa widoku jest nieprawidłowa");
  37. }
  38. }
  39.  
  40. public static void setStage(Stage _stage){
  41. stage = _stage;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement