我想在控制器中调用视图方法,但我不知道如何:)我寻求的例子,但我没有找到它.我可以在这段代码中执行此操作吗?我是否必须重新建造它?我使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
我的控制器(这里我想调用gotoRegister()方法)
public class SampleController {
public SampleModel model = new SampleModel();
@FXML
protected Text actiontarget;
@FXML
protected PasswordField passwordField;
@FXML
protected TextField loginField; …Run Code Online (Sandbox Code Playgroud)