타임 라인 애니메이션을 사용하여 이미지 배열의 애니메이션을 만들고 있습니다. 배열은 299 개 이미지입니다. 0에서 298까지 이미지를 한 번 반복 한 다음 애니메이션을 중단합니다.javafx 응용 프로그램에서 이미지를 사용하는 애니메이션이 작동하지 않습니다.
계속 애니메이션을 적용해야하지만 작동하지 않아야합니다. 타임 라인 애니메이션을 사용하여 각 이미지 뷰에 대해 opacityProperty()를 사용하고 있습니다. 하나의 이미지 애니메이션이 완료되면 다음 이미지로 이동합니다. 하지만 298 이미지에 도달하면 계속 반복 할 수 없습니다. 변수 x는 0이되어야하고 애니메이션을 다시 시작해야합니다.
public class Animation_Program_version3 extends Application {
Timeline timeline = null;
Group rootGroup = null;
int x = 0;
Image [] images = new Image[299];;
ArrayList imageview = null;
public Animation_Program_version3() {
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Welcome");
rootGroup = new Group();
final Scene scene = new Scene(rootGroup, 800, 400, Color.BEIGE);
imageview = new ArrayList();
int y = 0;
for(int x = -50; x < 100; x=x+1){
images[y] = new Image("/Image"+x+".jpg", true);
imageview.add(new ImageView(images[y]));
y = y+1;
}
int y1 = 150;
for(int x = 99; x > -50; x=x-1){
images[y1] = new Image("/Image"+x+".jpg", true);
imageview.add(new ImageView(images[y1]));
y1 = y1+1;
}
rootGroup.getChildren().addAll(imageview);
int x = 0;
timeline = new Timeline();
doAnimation();
primaryStage.setScene(scene);
`primaryStage.show(); `
}
<code>
public void doAnimation(){
KeyFrame[] kf = new KeyFrame[images.length];
ImageView im = (ImageView)imageview.get(x);
<code>
im.setImage(images[x]);
kf[x] = new KeyFrame(Duration.millis(1), new KeyValue(im.opacityProperty(), 0));
timeline.getKeyFrames().add(kf[x]);
// When timeline animation is finished it executes the seetOnFinished Event
timeline.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if(x == 298){
System.out.println("VALUE OF x:"+x);
x=0; -------> This is where code does not work When it reaches end of array and x initialize to 0 then animation stops.
Collections.reverse(imageview);
doAnimation();
}
/* This if loop works fine animation iterates through 0 to 298 images. */
if(x < 298){
x++;
doAnimation();
}
}
});
timeline.play();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
내 프로그램을 수정했지만 이제는이 오류가 발생하지 않습니다. java.lang.IllegalArgumentException : 어린이 : 중복 어린이.
하지만 여전히 문제는 프로그램이 화면에서 실행되는 것을 볼 수 없다는 것입니다. 화면에 루트 그룹을 추가했지만 아무 것도 볼 수 없습니다. 내 새 프로그램 :
public class Animation_Program_version3 extends Application {
Timeline timeline = null;
Group rootGroup = null;
int x = 0;
Image [] images = new Image[299];;
ArrayList imageview = null;
ImageView im = new ImageView();
public Animation_Program_version3() {
// this.imageview = new TreeSet();
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Welcome");
rootGroup = new Group();
final Scene scene =
new Scene(rootGroup, 800, 400, Color.BEIGE);
//
// final Scene scene =
// new Scene(rootGroup, 800, 400, Color.BEIGE);
// int x = 0;
//Image [] images =
imageview = new ArrayList();
int y = 0;
for(int x = -50; x < 100; x=x+1){
images[y] = new Image("/Image"+x+".jpg", true);
imageview.add(new ImageView(images[y]));
y = y+1;
}
int y1 = 150;
for(int x = 99; x > -50; x=x-1){
images[y1] = new Image("/Image"+x+".jpg", true);
imageview.add(new ImageView(images[y1]));
// imageview[y1] = new ImageView(images[y1]);
y1 = y1+1;
}
//for (int i = 0; i < 299; i++) {
// rootGroup.getChildren().addAll(imageview);
//}
int x = 0;
timeline = new Timeline();
doAnimation();
primaryStage.setScene(scene);
primaryStage.show();
}
public void doAnimation(){
KeyFrame[] kf = new KeyFrame[images.length];
// im = (ImageView)imageview.get(x);
im.setImage(images[x]);
rootGroup.getChildren().setAll(im);
kf[x] = new KeyFrame(Duration.millis(1), new KeyValue(im.opacityProperty(), 0));
timeline.getKeyFrames().add(kf[x]);
timeline.setOnFinished(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
// timeline = null;
if(x == 298){
System.out.println("VALUE OF x:"+x);
x=0;
// Collections.reverse(imageview);
// rootGroup.getChildren().setAll(imageview);
//
doAnimation();
}
if(x < 298){
System.out.println("Inside 298 OF x:"+x);
x++;
// Animation_Program_version3.rootGroup = null;
// Animation_Program_version3.rootGroup = new Group();
doAnimation();
}
}
});
timeline.play();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
당신이 특정 오류를받을 수 있나요 확장? 또한 질문을 다시 포맷하십시오. – Pieter
'java.lang.IllegalArgumentException : Children : duplicate children'을 던지는 코드가 문제입니까? – aKilleR
문제를 해결 했으므로 이제 java.lang.IllegalArgumentException이 발생하지 않을 것입니다. 자식 : 중복 자식 오류 – Mike