내 창에 내 배경색을 1 초 동안 설정 한 다음 투명하게 전환해야합니다. 이 설정을 사용하여 배경색을 변경하고 1000ms의 지속 시간을 가진 TimeLine을 사용하여 일시 중지 한 다음 투명하게 전환합니다.JavaFX 타임 라인을 사용하여 프로그램 일시 중지
타임 라인이 일시 중지되어 있지 않고 프로그램이 지나쳐서 너무 빨리 배경을 투명하게 설정하고 있습니다. 누구든지이 문제를 해결하는 방법을 알고 있습니까?
이 프로젝트의 범위 때문에 thread.sleep 또는 이와 비슷한 것을 사용할 수 없습니다.
package assign3;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import javafx.animation.FillTransition;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Question2 extends Application
{
public static final int RED = 1;
public static final int GREEN = 2;
public static final int BLUE = 3;
public static final int ORANGE = 4;
@Override
public void start(Stage obPrimeStage) throws Exception
{
boolean runGame = true;
int level = 1;
BorderPane obBorder = new BorderPane();
HBox obPane = new HBox();
HBox obStart = new HBox();
Button btRed = new Button("Red");
Button btGreen = new Button("Green");
Button btBlue = new Button("Blue");
Button btOrange = new Button("Orange");
Button btStart = new Button("Start");
Timeline pause = new Timeline();
pause.setCycleCount(1);
pause.getKeyFrames().add(new KeyFrame(Duration.millis(1000)));
obStart.getChildren().add(btStart);
obPane.getChildren().addAll(btRed, btGreen, btBlue, btOrange);
obBorder.setCenter(obPane);
obBorder.setBottom(obStart);
obPane.setAlignment(Pos.CENTER);
obStart.setAlignment(Pos.CENTER);
Scene obScene = new Scene(obBorder, 400, 400);
obPrimeStage.setTitle("Question 2");
obPrimeStage.setScene(obScene);
obPrimeStage.show();
ArrayList<Integer> colours = new ArrayList<>();
ArrayList<Integer> guesses = new ArrayList<>();
btStart.setOnAction((ActionEvent start) -> {
for(int i = 0; i <= level; i++)
{
int randomColour = (int)((Math.random() * 4) + 1);
randomColour = 1;
if(randomColour == RED)
{
obBorder.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
pause.play();
obBorder.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
colours.add(RED);
}
대단히 감사합니다. 이것은 그것을 완벽하게 대답했다. KeyFrames의 작동 방식에 대해서는 완전히 확신 할 수 없었습니다. –