【发布时间】:2017-05-08 10:02:53
【问题描述】:
我正在寻找一个示例,当某个变量 x 将值 1 变为 y.png 时,需要更改 动态图像x.png,当这个变量回到 0 时恢复旧图像。如果这是可能的,怎么办?感谢帮助
我正在尝试使用此代码但没有成功...
这是我的控制器类
public class FXMLDocumentController implements Initializable {
@FXML
private ImageView myImage;
@Override
public void initialize(URL url, ResourceBundle rb) {
Random random = new Random();
while (true) { // <-- this is the problem how i can do that without while(true)??
int x = random.nextInt(1);
if (x == 0) {
Image image = new Image(getClass().getResource("x.png").toExternalForm());
myImage.setImage(image);
}
if (x == 1) {
Image image = new Image(getClass().getResource("y.png").toExternalForm());
myImage.setImage(image);
}
}
}
}
【问题讨论】:
-
所以你想要的行为是图像在 x 和 y 之间闪烁?
-
是的,是否制作闪烁的图像并不重要