为什么FadeTransition在当前线程完成时播放?

时间:2018-05-17 03:38:24

标签: java animation javafx javafx-8 javafx-2

当我调用REST API时,我希望淡出登录窗口。我使用FadeTransition但它从当前线程完成开始。我想首先淡化LoginWindow,而不是进一步执行代码。以下是我的代码:

public void login() throws IOException
{
    logger.info("username = " + username.getText() + ", password = " + password.getText());

    FadeTransition ft = new FadeTransition(Duration.millis(100), loginAnchorPane);
    ft.setFromValue(1.0);
    ft.setToValue(0.5);
    ft.play();



    Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(username.getText());
    if (!matcher.matches())
    {
        errorLabel.setText(resourceBundle.getString("invalid_email"));
        return;
    }

    if (StringUtils.isEmpty(password.getText()))
    {
        errorLabel.setText(resourceBundle.getString("invalid_password"));
        return;
    }

    errorLabel.setText("");

    System.out.println("first line " + new Date());
    boolean success = userService.login(username.getText(), password.getText());
    System.out.println("second line " + new Date());

}

它打印第二行,然后在LoginWindow淡出之后。我想首先淡化LoginWindow,然后打印first linesecond line

我已尝试过Platform.runLaternew Thread(),但这也无效。 如何在执行下一行之前立即播放动画?

0 个答案:

没有答案