我有一个自定义异常类,想if-else
使用三元运算符而不是标准运算符,但由于某种原因发生了错误。
如果事件为正,则值应该改变,如果为负,则应该抛出异常。
新手。我正在学习JavaFX并使用SceneBuilder
.
我设定的任务:
Pin Code
“启动应用程序后,对象中的铭文Label
会在短时间内逐行显示(理想情况下,同时添加声音)。”
据我了解,您需要延迟一个周期。
我在控制台中检查了我的代码,它正确地逐行输出,但据我了解(如果这是错误的,请纠正我),该方法initialize()
首先通过,然后才用全文启动场景。
我尝试将其分离到方法中并在帮助下进行查看PauseTransition
,但没有帮助。
我也尝试过Thread.sleep()
,但结果是一样的,首先进行初始化,然后才显示场景。
入口控制器类:
import javafx.animation.PauseTransition;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.util.Duration;
public class EntryController {
@FXML
private Label printPinCode;
public void pause(String text) {
PauseTransition wait = new PauseTransition(Duration.seconds(1));
wait.setOnFinished((e) -> {
printPinCode.setText(text);
wait.playFromStart();
});
wait.play();
}
@FXML
void initialize() {
String textStartWindow = "Pin Code";
String newText = "";
for (int i = 0; i < textStartWindow.length(); i++){
newText += textStartWindow.charAt(i);
pause(newText);
}
}
主要类别:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/form/pin-code.fxml"));
stage.setTitle("ATM --> Start");
stage.setScene(new Scene(root));
stage.show();
}
}