The first problem is, I can't get the read values in the paint method in my appleTree subclass; I tried printing it out and whatever I do it says all values are 0s and "null"s.
Trees trees = new Trees();
int t = trees.getX();
This code is taken from your previous post, take a close look at it.
Where do you set values for the fields of your Tree
?
Not in your constructor, and you don't call any setter, so it gets initialized to a default value, which is null
in case of reference types, and 0
in case of integral types.
I'm not sure if this is what you mean but t also gave "0" back when i tried printing it out.
You have to call getX()
and getY()
in the paint()
method of the Tree
object that you initialized with the data from your file.
I can use appleTree.paint(g); but that only draws out one tree, I guess I should call that paint() method on every appleTree
Yes.
I just don't see how and where.
In your class that reads the file you can write a method that returns a Collection
of Tree
objects. In your GUI code you call that method, and a Collection<Tree>
is returned.
Iterate over that collection and call paint()
for every Tree
.
BTW, throughout my post I refer to your Trees
as Tree
. Why exactly did you call it that …