【发布时间】:2016-03-17 01:14:44
【问题描述】:
我正在做 java fx,我陷入了将变量传递到不同的 FXML 场景中。所以在第一个场景控制器上,LoginController 与 Login.fxml 相关联
public class LoginController {
@FXML private TextField username;
@FXML private PasswordField password;
@FXML private Button loginButton;
@FXML private Label labelStatus;
@FXML private void handleLoginButton() throws InterruptedException {
try {
FXMLLoader mainLoad = new FXMLLoader(getClass().getResource("../View/mainscreen.fxml"));
Parent mainRoot = (Parent) mainLoad.load();
Stage stage = new Stage();
stage.setScene(new Scene(mainRoot));
stage.show();
} catch (Exception e) {
e.printStackTrace();
return;
}
}
}
当新场景打开时,我需要根据包含用户输入的用户名变量设置标签。这意味着我们需要通过控制器将变量从 Login.fxml 传递到 mainscreen.fxml。我如何做到这一点?
【问题讨论】: