コントローラーでビューメソッドを呼び出したいのですが、方法がわかりません:)例のように探しましたが、見つかりませんでした。このコードでそれを行うことはできますか? 私はそれを新たに構築する必要がありますか?私は javafx と fxml テクノロジを使用しています (ユーザー インターフェイスを構築するため)。
私のビューファイル( gotoRegister() と gotoLogin() メソッドがあります(それらを呼び出したい))
public class FXMLExampleMVC extends Application{
protected Parent root;
@Override
public void start(Stage stage) throws Exception {
gotoLogin();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("JavaFX Welcome!");
scene.getStylesheets().add(FXMLExampleMVC.class.getResource("cssforapp.css").toExternalForm());
stage.show();
}
public void gotoRegister() throws IOException{
root = FXMLLoader.load(getClass().getResource("RegisterFXML.fxml"));
}
public void gotoLogin() throws IOException{
root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
}
public static void main(String[] args) {
launch(args);
}
}
私のコントローラー(ここでは gotoRegister() メソッドを呼び出したい)
public class SampleController {
public SampleModel model = new SampleModel();
@FXML
protected Text actiontarget;
@FXML
protected PasswordField passwordField;
@FXML
protected TextField loginField;
@FXML protected void handleSubmitButtonAction(){
if((loginField.getText().equals(model.returnLogin()))&&(passwordField.getText().equals(model.returnPass())) ){
actiontarget.setText("You have access !");
} else {
actiontarget.setText("Wrong data !");
}
}
@FXML protected void handleSubmitButtonRegister() throws IOException{
//
//Here I want to invoke gotoRegister
//
}
}
私の質問: gotoRegister を呼び出すことはできますか? または、fxmlファイルを(コントローラーから)変更する他の方法はありますか?