Added Scene Replacement.

This commit is contained in:
Fan-Wu Yang
2017-04-04 18:19:41 +12:00
parent 37ebdb5145
commit 1516fc3916
9 changed files with 65 additions and 12 deletions
+21 -11
View File
@@ -6,6 +6,9 @@ import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import model.SceneCode;
import java.io.InputStream;
/**
@@ -13,14 +16,20 @@ import javafx.stage.Stage;
*/
public class Main extends Application {
public void start(Stage stage) throws Exception {
private Stage primaryStage;
FXMLLoader loader = new FXMLLoader(getClass().getResource("scenes/main.fxml"));
Parent root = loader.load();
Scene scene = new Scene(root, 500, 400);
public void start(Stage stage) throws Exception {
this.primaryStage = stage;
replaceSceneContent(SceneCode.MAIN);
//FXMLLoader loader = new FXMLLoader(getClass().getResource("scenes/main.fxml"));
//Parent root = loader.load();
//Scene scene = new Scene(root, 500, 400);
stage.setTitle("UC RSS");
stage.setScene(scene);
//stage.setScene(scene);
stage.show();
}
/**
@@ -31,19 +40,20 @@ public class Main extends Application {
*/
public Initializable replaceSceneContent(SceneCode fxml) throws Exception {
FXMLLoader loader = new FXMLLoader();
InputStream in = getClass().getClassLoader().getResourceAsStream(fxml.getFilePath());
InputStream in = getClass().getClassLoader().getResourceAsStream(fxml.getPath());
Parent page;
try {
page = (Parent) loader.load(in);
} finally {
in.close();
}
while(mainContainer.getChildren().size() > 1) {
mainContainer.getChildren().remove(1);
Scene scene = null;
if (fxml.isLoadMenu()){
}else {
scene = new Scene(page, SceneCode.prefWidth, SceneCode.prefHeight);
}
mainContainer.getChildren().add(page);
//change session code to fit with the serialisation
session.setSceneDisplayed(fxml);
primaryStage.setScene(scene);
return (Initializable) loader.getController();
}
}
+31 -1
View File
@@ -1,8 +1,38 @@
package model;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import java.io.IOException;
import java.io.InputStream;
/**
* Created by fwy13 on 4/04/17.
*/
public enum SceneCode {
MAIN()
MAIN("main", false);
private String path;
private boolean loadMenu;
public static int prefWidth = 1200;
public static int prefHeight = 900;
SceneCode(String path){
this(path, true);
}
SceneCode(String path, boolean loadMenu){
this.path = path;
this.loadMenu = loadMenu;
}
public String getPath() {
return path;
}
public boolean isLoadMenu() {
return loadMenu;
}
}
+13
View File
@@ -0,0 +1,13 @@
package model;
/**
* Created by fwy13 on 4/04/17.
*/
public class Session {
private String userCode;//this is like fwy13
public Session(){
}
}
View File
Binary file not shown.
View File
Binary file not shown.
Binary file not shown.