当我调用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 line
和second line
。
我已尝试过Platform.runLater
和new Thread()
,但这也无效。
如何在执行下一行之前立即播放动画?