import java.awt.*;
import javax.swing.*;

public class DrawShapes1 extends JApplet
{
   private Shape[] shapes;

   public void init()
   {
     shapes = new Shape[4];                    // array of 4 shapes
     shapes[0] = new Circ2(10, 20, 5);         // creating 2 circles
     shapes[1] = new Circ2(30, 20, 5);

     shapes[2] = new Rect2(0, 10, 50, 10);     // creating 2 rectangles
     shapes[3] = new Rect2(10, 0, 30, 10);
     setBackground(Color.yellow);
   }

   public void paint(Graphics g)
   {
     for (int i=0; i<shapes.length; i++)       // loop over all shapes
     {
       if (shapes[i] instanceof Rect2)
       { 
          Rect2 r = (Rect2)shapes[i];          // casting Shape obj. to Rect
          r.draw(g);                           // in order to apply its draw()
       }                                       // method
       if (shapes[i] instanceof Circ2)
       {
          Circ2 c = (Circ2)shapes[i];          // casting Shape obj. to Circ
          c.draw(g);                           // in order to apply its draw()
       }                                       // method
     }
   }
}
