Код: Выделить всё
@FXML
void OnKeyPressed(KeyEvent event) {
System.out.println(event);
userChoicesLabel.setVisible(true);
if (userChoices.size() < 4 || event.getCode() == KeyCode.BACK_SPACE) {
switch (event.getCode()) {
case KeyCode.W:
if (!userChoices.contains("c")) {
userChoices.add("c");
}
break;
case KeyCode.A:
if (!userChoices.contains("b")) {
userChoices.add("b");
}
break;
case KeyCode.S:
if (!userChoices.contains("d")) {
userChoices.add("d");
}
break;
case KeyCode.D:
if (!userChoices.contains("a")) {
userChoices.add("a");
}
break;
case KeyCode.BACK_SPACE:
if (userChoices.size() > 0) {
userChoices.removeLast();
System.out.println("Deleted last char");
}
break;
default:
break;
}
String currentChoices = "";
for (String choices : userChoices) {
currentChoices += choices;
}
userChoicesLabel.setText(currentChoices);
}
Код: Выделить всё
Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), e ->{
// some code
}));
upArrowView.setVisible(false);
leftArrowView.setVisible(false);
rigthArrowView.setVisible(false);
downArrowView.setVisible(false);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
Есть ли способ заставить OnKeyPressed работать, пока временная шкала все еще активна?
Подробнее здесь: https://stackoverflow.com/questions/784 ... ing-called