Problems with data transmission in javafx and reuse variables

与世无争的帅哥 提交于 2019-12-09 13:54:12

问题


My program is structured package as follows -Browser.fxml -Elements.fxml

+BrowserController : Browser transmit values url to Elements

@FXML
void txtURL(ActionEvent event) {
    Pane pnLoad = fxmlLoader.load(getClass().getResource("Elements.fxml").openStream());
    FunctionController controller = (FunctionController) fxmlLoader.getController();
    controller.viewURL(txtURL.getText()); 
}

+ElementsController :, -With reading after I can only use the value url once for function viewURL

    @FXML
    public void viewURL(String url) {
        System.out.println(url);
    }

+How can I use the url again?

    @FXML
    void btnReviewUrl(ActionEvent event) {
      System.out.println(url);
    }

Please help me!


回答1:


You can create a Static variable in your class and assign the url value to that variable to ve used again anf across classes

 public static String urlValue;

@FXML
public void viewURL(String url) {
    System.out.println(url);
    urlValue =  url;
}


来源:https://stackoverflow.com/questions/40128271/problems-with-data-transmission-in-javafx-and-reuse-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!