I’m new to Java and JavaFX I have php,javascript,HTML experience… I’m trying to create a GUI for doing math and showing the results using javaFX text objects. I have a constructor method to create each text object based on its input. Then I have another constructor method which would call the previous one several times creating multiple text objects, but I can’t get this to work because it won’t let me define the new text objects based on the methods input ex:
public function(variable)
{
Text variable = new Text();
}
The problem is that each time the program is run there would be a different amount of text objects on screen, so I’m not sure how to accomplish the naming convention when I won’t know the total # of objects beforehand.
Also how would I add them all to the scene at the end. Would the constructor method add each to a group as they are created and then the whole group would get added with the get children method?
A more general idea of what I want to create:
The program would start with 10 text items on the screen. The user could click on two objects and choose to add/subtract/multiply them together, and then another text label would be created with the answer after processing the event. The new one could then be used to create another answer, and another and so on…
Maybe I’m approaching this totally wrong, let me know how you would approach it.
-back to my initial question, I could name the starting 10 statically if I wanted, but I’ll need to know how to do it dynamically to add more I think… …or maybe I’m waaay off…
Thanks in advance,
Brad
You want to use some sort of simple collection, like an
ArrayorList. You may want to read through the Collections tutorials for Java. For your program, the simplest approach would probably be an array of Text objects: