//grid with proposals

import java.awt.*;
import java.applet.*;

public class tmpanalysis extends java.applet.Applet
{
     int  nCols;     // defines number of rows and columns of board
    // float cellValue[];   // array of floats in grid cells
    int cellWidth;       // width of cell in pixels
	int cellHeight;      // height of cell in pixels
    int figw,figh,xsquare,ysquare,appw,apph,number;
    int xRef, yRef,y,x, ncols;
    float cellValue[]=new float[24];
    int nbars;
    //float cellValue[]={1,2,3,4,35,6,34,29,32,8,9,11,10,12,13,15,14,17,16,18,19,20,21,22,23,24};

	public void init(){
        xRef=x;
        yRef=y;
        nCols = 24;

	   // find size of applet
	   appw=size().width;
	   apph=size().height;

       //set size of squares in relation to applet size
       cellWidth=appw/25;
       cellHeight=apph/5;

        //starting position of first cell
        xsquare=appw/25;
        ysquare=apph/5;
	    }

	    //function to setT[];

        public void setTmp(float T[])
        {
        for(int i = 0; i<24; i++)
        cellValue[i] = T[i];
        repaint();
        }

    	public void paint (Graphics g)
    	{
		int xleft, ytop, incrementy, incrementx;

        //set initial values of design variables which are affected by the loop
        xleft=appw/25;
        ytop=apph/5;
        incrementx=appw/25;
        incrementy=apph/5;

        //to draw the numbers and letters
	    //first the letters
        g.drawString ("CD",1,(apph*3)/10);
        g.drawString ("CV",1,(apph*3)/10+cellHeight);
        g.drawString ("RD",1,(apph*3)/10+2*cellHeight);

        g.drawString ("Indiferente Reducir",cellWidth,(apph-apph/18));
        g.drawString ("Incrementar Reducir",cellWidth*9,(apph-apph/18));
        g.drawString ("Incrementar Reducir",cellWidth*17, (apph-apph/18));

        g.setColor (Color.red);
        g.fillRect(cellWidth*3,(apph-apph/18)+1,cellWidth,(apph/20));
        g.setColor (new Color (255,190,190));
        g.fillRect(6*cellWidth,(apph-apph/18)+1,cellWidth,(apph/20));

        g.setColor (new Color (0,0,170));
        g.fillRect(cellWidth*11,(apph-apph/18)+1,cellWidth,(apph/20));
        g.setColor (new Color (100,100,255));
        g.fillRect(cellWidth*14,(apph-apph/18)+1,cellWidth,(apph/20));

        g.setColor (new Color (255,255,0));
        g.fillRect(cellWidth*19,(apph-apph/18)+1,cellWidth,(apph/20));
        g.setColor (new Color (255,255,220));
        g.fillRect(cellWidth*22,(apph-apph/18)+1,cellWidth,(apph/20));

        g.setColor (Color.black);
	    //now the number for the hours
        number=0;
        for (int n=1; n<=24; n++)
        g.drawString (""+n,(((appw*3)/52)+(n-1)*incrementx)-7,apph/6);

	    // draw colors according to thermal proposal
	    xRef = xleft;
        y = ytop;

	    // Analysis for Conduction
	    for (int i=0; i<nCols; i++)
        {

        if (cellValue[i]<15 || cellValue[i]>29)
        {
       g.setColor (new Color (255,190,190));
       g.fillRect(xRef+i*cellWidth,y,cellWidth,cellHeight);
        }

        else
        {
        g.setColor (Color.red);
        g.fillRect(xRef+i*cellWidth,y,cellWidth,cellHeight);
  	    }
  	    }

	    //Analysis for convection

        //I must move the cells down one row
        y=y+incrementy;

        for (int j = 0; j<nCols; j++)
        {
        if (cellValue[j]>21 && cellValue[j]<32)
        {
        g.setColor (new Color (0,0,170));
        g.fillRect(xRef+j*cellWidth,y,cellWidth,cellHeight);
        }

        else if (cellValue[j]<=21)
        {
        g.setColor (new Color (100,100,255));
        g.fillRect(xRef+j*cellWidth,y,cellWidth,cellHeight);
        }

        else if (cellValue[j]>=32)
        {
        g.setColor (new Color (100,100,255));
        g.fillRect(xRef+j*cellWidth,y,cellWidth,cellHeight);
    	}
    	}

	    //Analysis for radiation

        //I must move the cells down one row
        y=y+incrementy;

        for (int k = 0; k<nCols; k++)
    	{
        if (cellValue[k]<=21)
        {
        g.setColor (new Color (255,255,0));
        g.fillRect(xRef+k*cellWidth,y,appw/25,apph/5);
        }

        else  if (cellValue[k]>21)
        {
        g.setColor (new Color (255,255,220));
        g.fillRect(xRef+k*cellWidth,y,appw/25,apph/5);
        }
        }
        g.setColor (Color.black);
        for (int n=0; n<3; n++)
        for (int m=0; m<24; m++)
        g.drawRect(xleft+m*incrementx,ytop+n*incrementy,cellWidth,cellHeight);

        g.drawString ("CD",1,(apph*3)/10);
        g.drawString ("CV",1,(apph*3)/10+cellHeight);
        g.drawString ("RD",1,(apph*3)/10+2*cellHeight);
        }


        }





