Reputation: 11
I am trying to create an array of Ellipse2D so I can later reset their positions in paintComponent(). It is not letting me initialise with an error under the Ellipse2D on line 3. What am I doing wrong?
Ellipse2D[] ellipses = new Ellipse2D[1000];
for(int i = 0; i <= 1000; i++){
ellipses[i] = new Ellipse2D(2,2,2,2);
}
Upvotes: 0
Views: 56
Reputation: 2715
From the Java document:
public abstract class Ellipse2D extends RectangularShape
The Ellipse2D class describes an ellipse that is defined by a framing rectangle.
This class is only the abstract superclass for all objects which store a 2D ellipse. The actual storage representation of the coordinates is left to the subclass.
And the following constructor definition:
protected Ellipse2D() This is an abstract class that cannot be instantiated directly.
The above documentation makes it clear that the Ellipse2D class cannot be initiated. An abstract class is meant to be extended by other classes. It basically contains common properties and methods needs by a bunch of other subclasses which shares the same properties and methods.
For Ellipse2D, it contains two nested subclasses (nested means the subclasses are defined inside Ellipse2D itself) which are Ellipse2D.Double and Ellipse2D.Float. You can initiate either of it and if you like assign it to Ellipse2D like this:
Ellipse2D[] ellipses = new Ellipse2D[1000];
for(int i = 0; i < 1000; i++){
ellipses[i] = new Ellipse2D.Float(2,2,2,2);
}
Upvotes: 1