0
전환 빌더를 사용하여 장면 작성기에서 생성 된 그림을 애니메이션화하려고합니다. 컨트롤러 :FXMLController에서 애니메이션이 작동하지 않습니다.
public class Controller{
@FXML
private Line line1;
@FXML
private Line line2;
@FXML
private Line line3;
@FXML
private Rectangle rectangle1;
private double mult_factor;
private double rectangle_height;
public Controller(){
final Animation anim = new Transition() {
{
setCycleDuration(Duration.millis(3000));
}
@Override
protected void interpolate(double frac) {
rectangle_height = rectangle1.getHeight();
mult_factor = frac * 5.8;
rectangle1.setHeight(rectangle_height * mult_factor);
}
};
}}
메인 클래스 :
public class FormTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("The container test");
primaryStage.setHeight(600);
primaryStage.setWidth(600);
Pane pane = (Pane) FXMLLoader.load(FormTest.class.getResource("conf.fxml"));
Controller ctr = new Controller();
primaryStage.setScene(new Scene(pane));
primaryStage.show();
}}
FXML 파일 :
장면이 바로 나타나지만 아무 일도 발생하지<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2" fx:controller="Controller">
<children>
<Line fx:id="line1" endX="100.0" endY="300.0" layoutX="106.0" layoutY="70.0" startX="100.0" />
<Line fx:id="line2" endX="100.0" endY="300.0" layoutX="300.0" layoutY="70.0" startX="100.0" />
<Line fx:id="line3" endX="193.0" layoutX="207.0" layoutY="370.0" />
<Rectangle fx:id="rectangle1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="42.0" layoutX="207.0" layoutY="327.0" stroke="BLACK" strokeType="INSIDE" width="192.0" />
</children>
</Pane>
, 애니메이션이 발생하지 않습니다. 내가 뭘 잘못하고 있니?
글쎄, 그 사실을 깨닫지 못했습니다. 고마워요. 하지만 지금은 왜 내가 NullPointerException을 받고 오전 이해가 안 돼요 rectangle_height = rectangle1.getHeight(); –
신경 쓰지 마라, 그것은 효과가있다, 나는 initialize 메소드를 추가하지 않았고 이제는 작동한다. 문제는 애니메이션이 내가하고 싶은 일을하는 것이 아니라 단지 사소한 또 다른 문제라는 것입니다. 도움 주셔서 감사합니다. –