
package interfazgrafica7;

import java.awt.Canvas;
import java.awt.Graphics;

public class AreaDibujo extends Canvas {
    
      private Componentes componentes;
      private int x1, y1, x2, y2;
      private boolean primerDibujado = true;
      private boolean inicioFigura = false;

    public AreaDibujo(Componentes componentes) {
        this.componentes = componentes;
    }
    
    public void paint(Graphics g) { 
       if (primerDibujado)
        {  g.drawString("AREA DE DIBUJO", 250, 20);
           g.drawLine(1, 1, 649, 1); 
           g.drawLine(1, 1, 1, 394); 
           g.drawLine(649, 1, 649, 394); 
           g.drawLine(1, 394, 649, 394); 
           primerDibujado = false; 
        }
    
       if (inicioFigura)
        { 
          switch(componentes.getTipoFigura()) 
          {
              case 1: g.drawLine(x1, y1, x2, y2);
                      break;
              case 2: g.drawRect(x1, y1, x2-x1, y2-y1);
                      break;
              case 3: g.drawOval(x1, y1, x2-x1, y2-y1);
                      break;                      
          }
          inicioFigura = false;
        }
    }

    public void update(Graphics g) { 
      paint(g);
    }
 
    public void recibirCoordenadas1(int x1, int y1) {
      this.x1 = x1;
      this.y1 = y1;
      inicioFigura = true;
    }

    void recibirCoordenadas2(int x2, int y2) {
       this.x2 = x2;
       this.y2 = y2;
    }   
}
