javafx中的数据传输问题和重用变量 [英] Problems with data transmission in javafx and reuse variables
本文介绍了javafx中的数据传输问题和重用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的程序结构化包如下
-Browser.fxml
-Elements.fxml
My program is structured package as follows -Browser.fxml -Elements.fxml
+ BrowserController:浏览器将值传递给元素url
+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 :,
-我只能使用后阅读函数viewURL的值url一次
+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);
}
请帮助我!
推荐答案
您可以在类中创建一个静态变量,并将url值分配给该变量,以便在类之间再次使用anf
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;
}
这篇关于javafx中的数据传输问题和重用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文