title: Paint ArrayList of Shape Objects to Frame
body: <p>I'm having difficulty with drawing Shapes (Circle &amp; Rectangle) into a Frame.</p>
  
  <p>I have created both a Circle and a Rectangle Class that implements the Shape Interface. I have then created  DrawableCircle and DrawableRectangle Classes that extend the Circle and Rectangle Classes appropriately, and implement the Drawable Interface.</p>
  
  <p>I am now trying to create a ShapesDriver Class which extends Frame and has within it the main method and paint(Graphics g) method. Within ShapesDriver I need to create an ArrayList of type Drawable. This ArrayList holds an instance of DrawableCircle and DrawableRectangle. In the paint method I have to iterate through the ArrayList and invoke the draw method for each shape.</p>
  
  <p>This is where I am stuck...</p>
  
  <p>Any help would be appreciated!</p>
  
  <p>Shape Interface</p>
  
  <pre><code>public interface Shape {
  
      public double area();
  
  }
  </code></pre>
  
  <p>Circle Class</p>
  
  <pre><code> public class Circle implements Shape{
  
          private int radius;
          private double area;
  
          public Circle(int r){
              radius = r;
  
          }
  
          @Override
          public double area() {
  
              area = Math.PI * (radius * radius);
              return area;
          }
  
  }
  </code></pre>
  
  <p>Rectangle Class</p>
  
  <pre><code>public class Rectangle implements Shape{
  
      double height;
      double width;
      double area;
  
      public Rectangle(double h, double w){
          height = h;
          width = w;
      }
  
      @Override
      public double area() {
          area = height * width;
          return area;
      }
  
  }
  </code></pre>
  
  <p>Drawable Interface</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  
  public interface DrawableInterface {
  
      public void setColor(Color c);
      public void setPosition(int x, int y);
      public void draw(Graphics g);
  
  }            
  </code></pre>
  
  <p>DrawableCircle</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  
  
  public class DrawableCircle extends Circle implements DrawableInterface{
  
      private Color col;
      private int posX;
      private int posY;
  
      public DrawableCircle(int r){
          super(r);
      }
  
      @Override
      public void setColor(Color c) {
          col = c;
      }
  
      @Override
      public void setPosition(int x, int y) {
          posX = x;
          posY = y;
      }
  
      @Override
      public void draw(Graphics g) {
  
          g.setColor(col);
          g.drawOval(posX, posY, 15, 15);
      }
  
  
  
  }
  </code></pre>
  
  <p>DrawableRectangle</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  
  
  public class DrawableRectangle extends Rectangle implements DrawableInterface{
  
      private Color col;
      private int posX;
      private int posY;
  
      public DrawableRectangle(double h, double w){
          super(h, w);
      }
  
      @Override
      public void setColor(Color c) {
          col = c;
      }
  
      @Override
      public void setPosition(int x, int y) {
          posX = x;
          posY = y;
      }
  
      @Override
      public void draw(Graphics g) {
  
      g.setColor(col);
      g.drawRect(posX,posY,10,10);
  
      }
  
  }
  </code></pre>
  
  <p>ShapesDriver</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Frame;
  import java.awt.Graphics;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  import java.util.ArrayList;
  
  
  public class ShapesDriver extends Frame {
  
  static ArrayList&lt;DrawableInterface&gt; shapesArr = new ArrayList&lt;DrawableInterface&gt;();
  
      public ShapesDriver() {
          super("Shapes Object Array");
          setSize(400, 300);
          setLocation(200, 200);
  
          setVisible(true);
      }
  
      public static void main(String[] args) {
  
  
          DrawableCircle c = new DrawableCircle(500);
          c.setColor(Color.GREEN);
          c.setPosition(25, 25);
  
          DrawableRectangle r = new DrawableRectangle(100, 50);
          r.setColor(Color.RED);
          r.setPosition(75, 75);
  
          shapesArr.add(c);
          shapesArr.add(r);
  
  
   ShapesDriver shapeFrame = new ShapesDriver();
  
           shapeFrame.addWindowListener(new WindowAdapter() {
              @Override
              public void windowClosing(WindowEvent e) {
                  System.exit(0);
              }
          });
  
      }
  
      @Override
      public void paint(Graphics g) {
  
          for (DrawableInterface s : shapesArr) {
              super.paint(g);
  
              s.draw(g);
          }
      }
  }
  </code></pre>