的控制器2我的JavaFX 2.0应用程序,它由两个FXML文件,和2个控制器,用于他们+一个“主” java文件。如何FXML控制器1创建的对象传递给内FXML控制
的开始时间,FXML1被初始化,这样的:
public void start(Stage stage) throws Exception {
stage.setTitle("Demo Jabber JavaFX Chat");
Parent root = FXMLLoader.load(getClass().getResource("fxml_example.fxml"),
ResourceBundle.getBundle("fxmlexample.fxml_example"));
Scene scene = new Scene(root, 226, 264);
stage.setScene(scene);
scene.getStylesheets().add("fxmlexample/fxmlstylesheet.css");
stage.show();
}
然后,点击从SCENE1按钮时,在控制器1类的事件处理程序,我改变SCENE1根,展现新的GUI - 查看用户。在这个控制器中,我初始化了一些对象。例如像这样:
public class FXMLExampleController {
//some fields...
private MySuperObject c;
@FXML protected void handleSubmitButtonAction(ActionEvent event) {
//some fields...
c = new MySuperObject(); //here i initialize my object, i'm interested in
try {
c.login(username, password); // some actions with this object, which i need to make.
Scene cc = buttonStatusText.getScene();
Parent root = null;
try {
//changing a scene content...
root = FXMLLoader.load(getClass().getResource("fxml_example2.fxml"),
ResourceBundle.getBundle("fxmlexample.fxml_example"));
} catch (IOException ex) {
Logger.getLogger(FXMLExampleController.class.getName()).log(Level.SEVERE, null, ex);
}
cc.setRoot(root);
}
而且,在那之后,我必须做一些工作,对下一场景的对象,而且它必须是不一样的类的新实例,但对象,我已经在第一个场景中初始化了。
我知道如何让这些全部采用“非标准的Java”,但我是那种对使用JavaFX + FXML这个任务的困惑。
什么root.cb. **分钟** .getItems()。add(“new item”);和** cc ** .setRoot(root);在最后的代码片? – 2012-05-23 11:37:03
对不起,'分钟'来自错误的复制粘贴。和来自维多利亚州原始代码样本的'cc'。更新。 – 2012-05-23 12:35:08