[英]How do I call an object an object from a .fxml file in my controller file?
我正在制作秒表程序,我想設置旋轉照片。 問題是,我不知道如何在控制器文件中調用照片。 它只是告訴我找不到符號。
這是我想從我的.fxml文件中調用的照片
<ImageView fx:id="hand">
<image>
<Image url="@hand.png"/>
</image>
</ImageView>
在我的控制器文件中將其命名為Heres,但出現錯誤。
@FXML
private void updateStopwatch(){
elapsedTime++;
Integer rotation = elapsedTime * 6;
hand.setRotate(rotation);
}
我在這里先向您的幫助表示感謝。 我得到的錯誤如下:
hand.setRotate(rotation);
^^^^
Cannot find symbol hand
給定fxml對象后,要將其正確的屬性fx:id="hand"
注入到控制器中,您需要將該id聲明為控制器類中的屬性。
public class MyController {
@FXML private ImageView hand;
private void updateStopwatch(){
elapsedTime++;
Integer rotation = elapsedTime * 6;
hand.setRotate(rotation);
}
}
在fxml文件中,必須通過在根元素中添加以下屬性來引用controller(MyController):
fx:controller="some.package.MyController"
您的fxml文件只能引用一個控制器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.