Search code examples
javafxtransmission

Problems with data transmission in javafx and reuse variables


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!


Solution

  • 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;
    }