1

I have a shape (don't know what kind of shape it is), and I want to create another shape that is exacly the same.

I've tried this (as dumb as it sound):

Shape b = a; (a beeing the shape I already have).

Here is the actual code (simplified):

    public class Box extends CenaVisivel {

            public Shape box = null;

            public Box(Shape shape){

                    box = shape;
                    ...
            }
    }

The problem of doing this is that the box and the shape ocuppie the same memory space (they are the same SAME! like, if you change one, you change the other), and I dont want that, I want diferent shapes that have the same properties.

  • 1
    There may be a few ways to misuse `Shape`'s functionality for this (intersecting with a `Rectangle` covering the whole shape; using `union` with an empty shape), otherwise it's a duplicate of this question: https://stackoverflow.com/questions/14180141/clone-javafx-node I strongly recommend implementing the copying functionality using a factory or something similar... – fabian May 30 '19 at 17:16
  • The problem is that the new shape will looks like the one I want but it will not have the same propreties. – Guilherme Da Bolsa May 30 '19 at 19:45
  • Plus it is not a duplicate of the question you pointed because i am not using fxml neither scene builder. – Guilherme Da Bolsa May 30 '19 at 19:47
  • 1
    You need to read the first paragraph of jewelsea's answer. – SedJ601 May 31 '19 at 01:45

0 Answers0