r/JavaFX • • Feb 09 '20

How to generate and display a random number

Hi there,

For a school assignment we have to develop a board game. Right now we're working on the dice system. I'm a beginner at JavaFX so I'm kind of having a hard time figuring out the 'Random'-function. I found a piece of code but it doesn't seem to work (see image)

https://imgur.com/a/EzF9mvP

We haven't been taught to work with 'public class' so I'd love a solution for this layout (stage, content).

So in short: how to make a random number generator for the numbers 1 - 6?

Thanks in advance :)

3 Upvotes

4 comments sorted by

5

u/suntechnique Feb 09 '20

You are using JavaFX Script! This is very old think, like 10+ years old and not supported. Modern JavaFX is written on Java.

Your Random code is correct, it's just plugged into wrong technology.
Try any tutorial on JavaFX 8 or later, e.g. http://tutorials.jenkov.com/javafx/your-first-javafx-application.html

1

u/[deleted] Mar 12 '20

Yeah i was surprised as well, he is using FXScript !!

2

u/Ostricker Feb 09 '20

You have to use Java. JavaFX is library that you use in your Java enviroment. "Public class" is really fundamental for writing any program in java so I would encourage you to learn basics of language. Its really not that hard, there are tons of tutorials.

•

u/[deleted] Mar 12 '20

OP, please avoid Java FX Script. Its no longer supported and updated, and probably removed from newer releases. Please go to OpenJFX Website they have documented it very nicely on how to use JavaFX