【发布时间】:2014-05-10 14:32:17
【问题描述】:
我有两个类 --menu 和 --game 他们都使用 fxml 文件来加载他们的场景场景到游戏类中的新场景
菜单:
public class menu extends application{
....
public void start(Stage stage) throws IOException{
StackPane loader = FXMLLoader.load(getClass().getResource("layout/startUp.fxml"));
stage.setScene(new Scene(loader));
stage.show();//show stage
}
....
}
游戏:
public class game{
public void start(Stage stage) throws IOException{
StackPane root = FXMLLoader.load(getClass().getResource("layout/game.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
}
}
菜单控制器:
public class menuController implements Initializable{
@FXML Button playButton;
@Override
public void initialize(URL location, ResourceBundle resources) {
playButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
/*
now i want to do something like this
*/
game g = new game();
g.start(stage);//this stage is from menu
}
});
}
有什么想法吗?在此先感谢
【问题讨论】:
-
如何将舞台传递给 menuController 或在 menuController 中隐藏菜单舞台?
标签: javafx