1

I am working on a Java Project and i want to do a simple display on a view. I heard that javaFx should be a good idea but I don't know if I'm going on the right way.

I have a basic array of boolean and i want to display it as a grid and put a dot or something else. here is an example: for the array {{1,0,1},{0,0,0},{1,1,0}}. I'd like to have image. And maybe some other variable (string, int) in the layout. Something close to an angular binding.

I have a main class launching a class "Foo" containing the data i want to display and doing some stuff modifying the data. My first idea was to use observer pattern with a new class "View" as observer and "Foo" as observable. And in my perfect world, when I create a new View I can create a new windows in the constructor, and update it in my update() method.

But I don't think I'm understanding right JavaFX because I think the only class that can be a javaFx Application is the main class and I don't understand how to use javaFx in my observer pattern.

Is there an easy way to do what i want? Should i change my architecture or use another graphic library?

dufaux
  • 681
  • 2
  • 8
  • 18
  • Maybe you could achieve this using a [`TableView`](https://docs.oracle.com/javafx/2/ui_controls/table-view.htm) otherwise you'd have to use a [custom painting approach](https://docs.oracle.com/javafx/2/canvas/jfxpub-canvas.htm) – MadProgrammer Jan 13 '16 at 23:48
  • For discussions about the structure, see http://stackoverflow.com/questions/32739199/javafx-software-design/32739723#32739723 and maybe http://stackoverflow.com/questions/32464698/ You should basically think of the `start` method as replacing the `main` method, but you can delegate any actual UI work to other classes from there if you choose. (Essentially it just ensures the FX toolkit is started.) The only caveat to that is that `start` is run on the FX Application Thread, so it must not block. – James_D Jan 14 '16 at 00:19
  • 2
    @MadProgrammer, most of the JavaFX 2 documentation now has a Java 8 specific version of the same documentation (at http://docs.oracle.com/javase/8/javase-clienttechnologies.htm), which is sometimes more up to date than the old JavaFX 2 documentation. For example [`TableView`](https://docs.oracle.com/javase/8/javafx/user-interface-tutorial/table-view.htm). Unfortunately, google often returns the JavaFX 2 hits, but if you look lower down in a google search results, often the Java 8 documentation will be listed. – jewelsea Jan 14 '16 at 00:48
  • In fact, I want to run a loop to update my array and print my array with Line and circle. But when I launch my javafx application, it lock the program and of course avoid my loop to be launched. In java swing i can just call update at each turn of my loop, but what i don't understand what is the best way in javafx. Should i launch my loop in a thread? – dufaux Jan 20 '16 at 13:17

0 Answers0