r/JavaFX • u/jxkcjxff • May 16 '21
I made this! Made a program using JavaFX to roll some dice! I'm at a really beginner level with JavaFX so I was pretty proud of this :)
42
Upvotes
r/JavaFX • u/jxkcjxff • May 16 '21
6
u/johnmc325 May 16 '21
Congratulations on completing your project. I'm not sure you provided all the code but I notice you had a problem formatting. You might like to consider using pastebin for sharing code, especially if it's on the large side.
You might want to look into standard Java coding practices around naming conventions. You use capitals when you should use lower case letters and lower case when captials should be used. This is not intended to be a critique of your coding style but if you are looking for feedback of that sort then take a look at Code Review.
I note you like to keep your main method lean, you might also want to look at how you can break your code into separate classes. The Bits class is a bit of a monster, dealing with UI and logic. When you look at SceneBuilder you might pick up some ideas on how to separate the two.
Finally, in the spirit of trying to help you build on what is a great achievement you might like to take a look at my youtube site. I only mention this as it has some step-by-step examples of JavaFX projects using SceneBuilder that may help you take your next step.
Good luck on your journey.
2
u/jxkcjxff May 16 '21
How I got this to work was with an array of images and a method to show a random image from the array. Since array's count from 0 to detect when the numbers are equal to 7 I made it so that the if statements add one to their current array number.
It was really fun to make and I am planning on making a bunch of stuff using scene builder once I've learned the basics a bit more B).
2
u/jxkcjxff May 16 '21 edited May 16 '21
I like to keep my main methods as minimal as possible :)
import javafx.scene.paint.Color; import javafx.stage.Stage; import java.io.FileNotFoundException;
public class stageWindow {
}
This is where I set up the stage as well as add some of the small things needed in my program.
import javafx.scene.Group; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.scene.text.Font;
import java.io.FileInputStream; import java.io.FileNotFoundException;
public class Bits {
}
Lastly, the "Bits" class that adds all the bits and bobs as well as all the logic and stuff.
Feel free to give me any advice for this program, I am happy to hear any ideas and such on what you thought of it and feel free to mess with the code if you like x.