Added Scene Replacement.
This commit is contained in:
+21
-11
@@ -6,6 +6,9 @@ import javafx.scene.Parent;
|
|||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
|
||||||
import javafx.stage.Stage;
|
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 class Main extends Application {
|
||||||
|
|
||||||
public void start(Stage stage) throws Exception {
|
private Stage primaryStage;
|
||||||
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("scenes/main.fxml"));
|
public void start(Stage stage) throws Exception {
|
||||||
Parent root = loader.load();
|
this.primaryStage = stage;
|
||||||
Scene scene = new Scene(root, 500, 400);
|
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.setTitle("UC RSS");
|
||||||
stage.setScene(scene);
|
//stage.setScene(scene);
|
||||||
stage.show();
|
stage.show();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,19 +40,20 @@ public class Main extends Application {
|
|||||||
*/
|
*/
|
||||||
public Initializable replaceSceneContent(SceneCode fxml) throws Exception {
|
public Initializable replaceSceneContent(SceneCode fxml) throws Exception {
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader();
|
||||||
InputStream in = getClass().getClassLoader().getResourceAsStream(fxml.getFilePath());
|
InputStream in = getClass().getClassLoader().getResourceAsStream(fxml.getPath());
|
||||||
Parent page;
|
Parent page;
|
||||||
try {
|
try {
|
||||||
page = (Parent) loader.load(in);
|
page = (Parent) loader.load(in);
|
||||||
} finally {
|
} finally {
|
||||||
in.close();
|
in.close();
|
||||||
}
|
}
|
||||||
while(mainContainer.getChildren().size() > 1) {
|
Scene scene = null;
|
||||||
mainContainer.getChildren().remove(1);
|
if (fxml.isLoadMenu()){
|
||||||
|
|
||||||
|
}else {
|
||||||
|
scene = new Scene(page, SceneCode.prefWidth, SceneCode.prefHeight);
|
||||||
}
|
}
|
||||||
mainContainer.getChildren().add(page);
|
primaryStage.setScene(scene);
|
||||||
//change session code to fit with the serialisation
|
|
||||||
session.setSceneDisplayed(fxml);
|
|
||||||
return (Initializable) loader.getController();
|
return (Initializable) loader.getController();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,38 @@
|
|||||||
package model;
|
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.
|
* Created by fwy13 on 4/04/17.
|
||||||
*/
|
*/
|
||||||
public enum SceneCode {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user