如何使用javafx在Gluon移动应用程序中切换视图? [英] How to switch views in Gluon mobile app using javafx?

查看:99
本文介绍了如何使用javafx在Gluon移动应用程序中切换视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javafx创建Gluon移动应用程序.我想创建一个登录页面,在该页面中,成功登录后,我需要在单击按钮时加载另一个(第二视图)视图.我没有得到合适的例子.如果有人知道这一点,请帮忙.我有两个视图:主演示者和辅助演示者(带有FXML的gluon应用程序).下面是主视图的控制器.

 公共类PrimaryPresenter {@FXML私人View主要;私人标签标签;@FXML私有TextField用户名;@FXML私人Button loginBt;私人警报警报;@FXML私人PasswordField密码;公共无效initialize(){primary.showingProperty().addListener((obs,oldValue,newValue)-> {如果(newValue){AppBar appBar = MobileApplication.getInstance().getAppBar();appBar.setNavIcon(MaterialDesignIcon.MENU.button(e->MobileApplication.getInstance().showLayer(ArjunsApp.MENU_LAYER)));appBar.setTitleText("Primary");appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e->System.out.println("Search"))));}});}@FXML私人void buttonClick(ActionEvent event){if(username.getText().equals(")){alert = new Alert(AlertType.ERROR,输入用户名");alert.showAndWait();}其他if(password.getText().equals(")){alert = new Alert(AlertType.ERROR,输入密码");alert.showAndWait();}别的{//加载我的辅助视图的代码}} 

}

解决方案

假设您正在使用带有FXML模板的Gluon插件-多视图项目,则可以使用 MobileApplication.getInstance().switchView(viewName)轻松切换视图.).

在您的情况下:

 <代码> @FXML私人void buttonClick(ActionEvent event){...MobileApplication.getInstance().switchView("SECONDARY_VIEW");} 

如果您使用的是Glisten-Afterburner模板(它也使用FXML),则可以使用以下内容:

 <代码> @FXML私人void buttonClick(ActionEvent event){...AppViewManager.SECONDARY_VIEW.switchView();} 

您可以在此处上找到有关Gluon Mobile API的更多信息./p>

I am trying to create a Gluon mobile application using javafx. I want to create a login page in which on a successful login i need to load another(Second View) view in a button click. I didn't get a proper example for this. If anyone knows this please help. I have two views Primary presenter and secondary presenter.(gluon application with FXML).Below is my primary view's controller.

public class PrimaryPresenter {

@FXML
private View primary;

private Label label;
@FXML
private TextField username;
@FXML
private Button loginBt;

private Alert alert;
@FXML
private PasswordField password;
public void initialize() {
    primary.showingProperty().addListener((obs, oldValue, newValue) -> {
        if (newValue) {
            AppBar appBar = MobileApplication.getInstance().getAppBar();
            appBar.setNavIcon(MaterialDesignIcon.MENU.button(e
                    -> MobileApplication.getInstance().showLayer(ArjunsApp.MENU_LAYER)));
            appBar.setTitleText("Primary");
            appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e
                    -> System.out.println("Search")));
        }
    });
}

@FXML
private void buttonClick(ActionEvent event) {
    if(username.getText().equals("")){
        alert = new Alert(AlertType.ERROR,"Enter username");
        alert.showAndWait();
    }else if(password.getText().equals("")){
        alert = new Alert(AlertType.ERROR,"Enter password");
        alert.showAndWait();
    }else{
        //Code to load my secondary view
    }
}

}

解决方案

Assuming you are using the Gluon plugin - Multi View project with FXML template, you can switch views easily with MobileApplication.getInstance().switchView(viewName).

In your case:

@FXML
private void buttonClick(ActionEvent event) {
    ...
    MobileApplication.getInstance().switchView("SECONDARY_VIEW");
}

If you are using the Glisten-Afterburner template instead (it also uses FXML), you could use something like:

@FXML
private void buttonClick(ActionEvent event) {
    ...
    AppViewManager.SECONDARY_VIEW.switchView();
}

You can find more about the Gluon Mobile API here.

这篇关于如何使用javafx在Gluon移动应用程序中切换视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆