Issue
I have a class: MyCircle. This is the constructor:
public MyCircle(Node view) {
this.view = view;
}
The instantiation in the other class:
Pane root = new Pane();
MyCircle obj = new MyCircle(new Circle(300, 200, 30, Color.BLUE));
root.getChildren().add(obj.getView());
How can I get/set the parameters of Circle?
The obj.getRadius()
can't work because the result is 0.0
Solution
Circle circle = (Circle) obj.getView();
circle.setRadius(50.0);
The point here is, that you store the Circle as a Node object. So you need to get the Node object and cast it to a Circle to set the radius.
Check, if you can store the Circle as a Circle instead of a Node. This makes life much easier and avoids instanceof checks or ClassCastExceptions.
Answered By - Jochen
Answer Checked By - Marilyn (JavaFixing Volunteer)