L
L
lonata2019-01-10 11:16:08
Java
lonata, 2019-01-10 11:16:08

How to animate a random character in a label in a JavaFX application?

I am writing an application in JavaFX and Scene Builder.
When I press the number 1 on the keyboard, a symbol is generated and assigned to the label. But this generation is static. There is no animation here. I would like to make character generation in the label animated. By type of slot machine, only instead of images, there will be symbols.
When the slot machine is running. it generates symbols for 2 seconds, slowly stops and shows some random symbol in the label.
Like this:
Slot machine
How can I do this?
Are there any libraries for this?

@FXML  private Label answerID; 

//generate random character and apply it to the label
private void generateChar() {
Random r = new Random();
String alphabet = "ABCDEFGHIKLMNOPQRSTUXYZ";
for (int i = 0; i < 25; i++) {
  String text = "" + alphabet.charAt(r.nextInt(alphabet.length()));
  answerID.setText(text);
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Alexandrov, 2019-01-10
@lonata

There is hardly anything ready, but doing this is not a problem. Write your component. The logic is extremely simple and can be implemented in several ways. Honest, but heavy or light, but
tricky. Hard, honestly, to twist the array, to start up a pre-rendered animation easily.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question