I am trying to draw graphics by calling the class Habitat in the code below.
I am calling it from a loop.
I am guessing this isn't the best way to do it as is it making multiple instances of the same name?
Sorry, new to Java so hope this makes sense.
public Habitat (int c,int w,int h,int[][] s) {
    habitatWidth = w;
    habitatHeight = h;
    plantSize = s;
    counter = c;
    p1 = new Plants(10,10,40,s);
}
public void paintComponent (Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                                           RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHints(rh);
    //sets background color
    Rectangle2D.Double r = new Rectangle2D.Double(0, 0, habitatWidth, habitatHeight);
    g2d.setColor(new Color(0, 0, 0));
    // fill the shape
    g2d.fill(r);
    //draw the plant p1
    p1.drawPlants(g2d);
}