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

public class DrawShapes2 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);             // background color
   }

   public void paint(Graphics g)            
   {
     for (int i=0; i<shapes.length; i++)      // loop over all shapes
     {
       Drawable d = null;
       if (shapes[i] instanceof Rect2)        
          d = (Rect2)shapes[i];               // casting Rect2 to Drawable
       if (shapes[i] instanceof Circ2)  
          d = (Circ2)shapes[i];               // casting Circ2 to Drawable

       d.draw(g);                             // draw shape
     }
   }
}
