• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create separate class for the simple line chart using JavaFx ?  RSS feed

 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to create separate class where i can place the line chart code.
The drawing chart code get from this link. Here is my code -



And this program throw exception.



Now, how can I separate the class Visualize and call from the another class ?
Thanks in advance.
 
Knute Snortum
Sheriff
Posts: 4209
124
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem seems to be that you can't have the two classes in the same file, because class Visualize needs to be public.
 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:The problem seems to be that you can't have the two classes in the same file, because class Visualize needs to be public.

Thanks a lot.
I have a question. Why this is necessary to be a public class ? I can access this class from the same package, but why this should be public is separate file ?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37398
531
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muztaba Hasanat wrote:
Knute Snortum wrote:The problem seems to be that you can't have the two classes in the same file, because class Visualize needs to be public.

Thanks a lot.
I have a question. Why this is necessary to be a public class ? I can access this class from the same package, but why this should be public is separate file ?

Because JavaFX is trying to run it as an application. Which means the JavaFX code (that you didn't write) needs to be able to access it.
 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:
Because JavaFX is trying to run it as an application. Which means the JavaFX code (that you didn't write) needs to be able to access it.

That is understandable. Thank you.
 
Muztaba Hasanat
Ranch Hand
Posts: 49
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have another problem in here. I am trying to pass data from outside from the Visualize class. Here is My code.
Main class from where Visualize class called.

Main Class


This is the Visualize class what responsible for showing the chart.
Visualize class.



When I ran the program this exception has been thrown.



I have tried to create a List inside the Visualize class then run the class. Same exception has been thrown.



So how can i pass the data from another class into the Visualize class so that this class can show the chart based on the whatever data passed into this class ?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!