[英]how to access a image variable in another button method in java fx
openButton.setOnAction((final ActionEvent X) -> {
File newfile = fileChooser.showOpenDialog(stage);
Image userselectedimage = new Image(file.toURI().toString());
more code
newactionbutton.setOnAction((final ActionEvent X) ->{
* i need access to the user selected image variable here *
}
我需要在另一個按鈕中訪問變量 userselectedimage(它是用戶選擇的背景圖像)。 由於 scope 是在 onclick 操作中定義的,是否有可能在另一個按鈕中訪問該變量? 我需要它,因為它是用戶選擇的圖片(它是用戶選擇的文件)。 我嘗試使用 static 變量在方法之外定義它,但這也不起作用,所以我沒有想法。
謝謝。
Image userselectedimage = null;
openButton.setOnAction((final ActionEvent X) -> {
File newfile = fileChooser.showOpenDialog(stage);
userselectedimage = new Image(file.toURI().toString());
}
newactionbutton.setOnAction((final ActionEvent X) ->{
userselectedimage.doSomething();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.