繁体   English   中英

如何在 java fx 的另一个按钮方法中访问图像变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM