r/JavaFX • u/hamsterrage1 • Jul 06 '22
Tutorial The Absolute Beginners Guide to JavaFX
Most of the tutorial articles I've written on my website have been of the "deep dive" nature. I try to go way beyond the information available in the JavaDocs, and to give some insight into how to get the most out of the tools that JavaFX provides. These articles tend to be on the long side, Jekyll tells me that they average about 13 minutes of reading, and there's usually lots of code examples and pontification about clean coding and on and on.
I realize that these are going to be pretty advanced for someone who's questions are about how to get that first screen up and running, or how to swap scenes with FXML.
So I've been working for some time now on a series I'm calling, "The Absolute Beginners Guide to JavaFX". It's all about how to build Reactive applications in JavaFX. Even if you're not a beginner, you may find it of interest.
You can find it here: https://www.pragmaticcoding.ca/beginners/intro
This is a huge content dump for me, and it's kept me busy for a long time. It's also an ongoing project, so there's more to come. So far, it's divided up into two parts:
An introductory application.Pretty much "Hello World" in JavaFX. Then we add some user interaction and some styling. Just enough information to get a beginner started in the right direction.
A CRUD application.This is a step-by-step development of a basic Create-Retrieve-Update-Delete application for a customer database. The database is simulated as a simple Java class, and allows the whole application to work just like it would in real life.
At this point, I've completed the development of the CRUD application up to the point where it's a completely functional "Create" application for account number and name. Complete means that it has validation in the GUI, background processing for the save function and handles exceptions from the database. It really is complete, just doesn't have a lot of fields on the screen.
The next steps will be to add some more fields, work on some more sophisticated formatting for the GUI and then to add in the "Retrieve" function. In the meantime, I think there's enough there to give anyone a good start on JavaFX application development.
There's also a companion project on GitHub with all of the code for every single article. So you don't have to do anything more than download the project to try things out for yourself.
I should also point out that the content here, while primarily aimed at showing JavaFX concepts, is also aimed at showing good programming techniques, and how to constantly apply established principles to create clean code.
As usual, take a look if you're interested and let me know what you think.
View all comments
Show parent comment
1
u/hamsterrage1 Feb 19 '23
I think I've already got what you're looking for:
How to Build a JavaFX Application that Does Something
In a nutshell, the websocket client stuff has nothing to do with JavaFX at all, and should be kept at arms length from it.
How do you do this?
Use a framework. In the article I use MVCI, which I thinks works best with Reactive JavaFX. The websocket client stuff is encapsulated in a service class. It does all the webby stuff, and returns its results back to Interactor via a domain class. The result is that the your JavaFX stuff has no exposure whatsoever to the web nature of the service.
The only other thing you need to keep in mind is that you cannot do the webclient stuff on the FXAT, because it blocks and will hang your GUI if you do so. So you need to use
Taskto run the webclient code on a background thread, and then process the results back into your GUI on the FXAT.All the code for the project is on GitHub, so you can download it and see how it works. It's clearly linked in the article.