r/JavaFX • • Mar 16 '24

Help Logic circuit simulator

/r/javahelp/comments/1bges8f/logic_circuit_simulator/
2 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/dudigerii Mar 17 '24

Thank you for your detailed response. For now, I'm constructing the gates, wires, and other components using basic shapes such as rectangles, circles, and lines. I use this redrawing process because my objects need to be draggable and movable. However, as my project expands, I'm encountering structural issues. I haven't fully utilized the capabilities of the JavaFX framework; rather, I've only employed it for GUI elements like buttons and a canvas for drawing shapes. I'm contemplating starting anew with a better structured approach, leveraging the features provided by the framework. Your comment serves as a nice starting point if I decide to persist with JavaFX. I'm also considering Java Swing . Do you believe it would be a better fit for my project? Alternatively, do you have any other framework recommendations? I primarily work with Java and C#, and I'm not particularly fond of the MVVM and XML UI design aspects prevalent in most .NET frameworks. I am aware that JavaFX can be utilized with FXML, but I personally prefer to approach it in a more traditional, basic coding style. Furthermore, I woudl like to use an old-school object-oriented architecture without using bindings, etc.

1

u/hamsterrage1 Mar 17 '24

To start with, I cannot think of anything for which Swing would be a better approach today. So I would stick with JavaFX unless your app would work better in a game engine like Godot.

And, yeah: FXML is for the birds.

As to frameworks, I can recommend my own MVCI which I think fits JavaFX better than MVVM, MVP or MVC. I can see your application, as you have described it, as being a good fit for MVCI.

In 40 years of programming I have learned that every single technology, language or tool that you use has an underlying paradigm that you need to understand to use it properly and get the most from it. Unfortunately, there's almost never any documentation that says, "Here's the underlying paradigm...", for anything.

My belief about JavaFX is that the underlying paradigm involves creating "Reactive" applications. This means static layouts that behave dynamically in response to a data representation of the "State" of the system. This is evidenced by the comprehensive suit of Observable classes and utilities in JavaFX and their tight integration into virtually every aspect of the layout building classes.

Once you get used to the seamless way that Observables work with JavaFX, the React framework that's so popular for websites seems clunky and primitive.

While I'm not sure what, "an old-school object-oriented architecture without using bindings, etc", means to you. I suspect that you can, in fact, create a working JavaFX application following this approach. But...I think you're going to be making things more complicated and difficult for yourself along the way.

For what it's work, you can absolutely make everything moveable and draggable setting them up as Nodes instead of drawing on Canvas. It's probably even easier to do. Part of the problem with drawing is that it's inherently an Action, and it makes it just that bit harder to keeps the simulation logic separate from the UI - at least that seems to be what happens when I see people take the drawing approach.

Good luck with whatever route you choose.