• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing Getters and Setters in JavaFX

 
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
QUESTION: How to access the legacy Java  getters from JavafX?

I have several legacy getters and setters from old codes that I wrote. Now I am using JavaFX and I cannot access these same getters.
In our example here, the setters are in a class called "Owner" and the data comes from a remote db, code snippet follows...


My old Getter-Setter class is typical for such. In any of the old apps, I would get the color with a simple
pulic String getChassisColor() { return chassisColor;}
This does not work anymore.

I am thumping through APress "Pro JavaFX 9" 4th edition by many authors, ppg 112-115 seem to point the way using JavaFX Beans, but seems very complex...

Is there something else I have not read up on in JavaFX? Some pointers to documentation and examples appreciated.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AhFai Chan wrote:In any of the old apps, I would get the color with a simple
pulic String getChassisColor() { return chassisColor;}
This does not work anymore.


What happens or doesn't happen?  I'm having trouble understanding what the problem is.
 
AhFai Chan
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java apps, whenever I use a getter-setter to "store" a set of data from the db, I simply create a class to do that and make a call to the setters. Then the set of data would be available to all other classes in the same package.
In JavaFX it seems I have to use bindings and properties, centered around views, controllers and models classes. All new to me.
I have not been able to get that working yet, still reading up on bindings and properties in the APress book.  
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even in a simple Java project, you have to hold an instance of the class in order to access the data, no?  One of the ways to do this is through "injection," basically passing an instance of the class that holds the data into another class. If you tell me what are the circumstances where you want to do this, I can help you more.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I'm trying to say is that Dependency Injection can be a more complex subject than binding in JavaFX.  If I know the problem you're trying to solve, I may be able to find a simpler solution.
 
AhFai Chan
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Requirements
*  My system is mainly in legacy Java, it has a 3-GL touch-and-feel to it and urgently needs to have a modern UI and graphs added to it.
*  It accesses a cloud mySQL, updates the db or download data from it using sprocs.
*  The data can be hundreds of records displayed line-by-line, they should be displayed in table format
*  They must also be graphed in XY-, bar- or pie-charts, or combinations thereof

Using helpful inputs from you, I have replaced the 3GL logon with FX, replaced the 3GL menu with the file-menu and submenu and I have no further issues with scenes, nodes and nodes-in-nodes. The UI begins to look friendly.

Problem Statement
* I can download the data and put them into a JSON array, and from there to any convenient array, but as of today, I still cannot display the downloaded data in FX's table views, text fields etc.
* Using the codes upstairs, in the first posting, how would I display the values for chassisColor and mobilePhone in FX? Using Java would be simple...

Am doing research using APress'es "Pro JavaFX9" by Vox, Chin, Gao et al.


I am not coming up to speed in FX as fast as I would like




 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am probably still not understanding the problem because it seems to me you would just fetch the data in the JavaFX class that builds the tables and graphs.  The fetching could be done using a DAO pattern (data access object).

Maybe show us a snippet of how it would be easy in plain old Java.
 
AhFai Chan
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I know what you mean. I'd like to try out a few things myself first as this is the first time I am using FX
From the downloaded data, I am trying to create an object, like this:

See whether I can retrieve as a static object, like this:


Thank-you for following up.
I am trying to understand the constructs "model", "view" and "collectors" and where and how ObservableList fits into them
The book is no helping much in clarifying them.

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the data can be static, then the solution is much easier.  If grapeTypes is static in the class Foo, then you can access it anywhere with Foo.grapeTypes.

Here is an old project I never finished, but it uses MVC and DAO patterns.
 
AhFai Chan
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for following up.

I have only one private static class using static fields and methods containing data about the user who has logged in. Many of the other classes store data from the cloud.

There's a chapter that talks about FX with enterprise modules, can you help me expand the Lambda expression in the codes:
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AhFai Chan wrote:I have only one private static class using static fields and methods containing data about the user who has logged in.


That doesn't sound good.  Are you only going to have one user logged in at a time?  Otherwise, the second user will clobber the data in the static field.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AhFai Chan wrote:please expand into an anonymous inner class


Why?  That would make the code more complex without any benefit.
 
AhFai Chan
Ranch Hand
Posts: 271
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About static class: it is my own development environment.

About not using lambda: its difficult to debug, Eclipse cannot step through the lambdas step by step and the stack trace is difficult to follow. Also, I am not following the flow of the code  when they are hidden from me.
I don't think books should use lambdas, authors can point to the advantage, being less typing, and give examples, but for us to follow the flow of the logic, it's best not to use lambdas.

Thanks, I think I have got that running, I needed to get a ListView with FX.Collections.getObservableArrayList();

One last thing b/4 signing off on this one:
If you are trying out code samples in book, pay particular attention to the ReST APIs the authors are using.
I have imported java-json.jar into \lib folder in most of my apps, but this particular book used jsonp_1.1_api.zip  which you can download here:
https://jcp.org/aboutJava/communityprocess/pr/jsr374/index.html

saves you hours of head-scratching...

 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AhFai Chan wrote:. . . About not using lambda: its difficult to debug, . . . .
I don't think books should use lambdas

In which case I think you should make your λs nice and simple, so they are easy to follow. I think you are better off learning λs as early in your career as possible, so you become familiar with them.

authors can point to the advantage, being less typing . . .

No, the principal advantage of λs is that they allow us to use a more functional style of programming.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

AhFai Chan wrote:About not using lambda: its difficult to debug,


You can use the peek() function to debug lambdas.

I don't think books should use lambdas, authors can point to the advantage, being less typing, and give examples, but for us to follow the flow of the logic, it's best not to use lambdas.


I don't think it's just less typing, I think the code is more expressive -- showing what you're doing, not just how you do it.

If you are trying out code samples in book, pay particular attention to the ReST APIs the authors are using.
I have imported java-json.jar into \lib folder in most of my apps, but this particular book used jsonp_1.1_api.zip  which you can download here:
https://jcp.org/aboutJava/communityprocess/pr/jsr374/index.html

saves you hours of head-scratching...


Yeah, the Pro JavaFX 9 book's source code on GitHub uses gradle, but without the dependencies you need.  Frustrating.  Thanks for the link.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your question isn't related to the subject line of the thread, start a new thread.
 
reply
    Bookmark Topic Watch Topic
  • New Topic