//file:win1.java 
//type:java code 
//note:LiBr Property Routine 
//author:Gautam Chatur & Partha Ghosh 
//date:12/3/97 to 12/13/97 

import java.util.*; 
import java.awt.*; 
import java.applet.Applet; 
import java.awt.*; 
import java.lang.Math.*; 

public class win1 extends Applet { 
  Panel pone,pai,pmr,pse,pcr,pl,pcc,pst,pupper,plower,pgo; 
  Font f1,f2,f3,f4,f5; 
  Label lmsg,ltype,lsys,lme,lt; 
  Button babout,binstru,bclear,bcal,bsi,ben; 
  TextArea round; 
  TextField bg,br; 
 // TextField round; 
  Checkbox cb1,cb2,cb3,cb4;    //only two of these can be selected 
  Checkbox cb5,cb6,cb7,cb8,cb9,cb10;            //dummy checkboxes 
  Checkbox cbSys1,cbSys2; 
  Checkbox cbType1,cbType2,cbType3; 
  CheckboxGroup cbSys,cbType; 
  ConversionPanel 
enthPanel,mfractPanel,tempPanel,prePanel,condPanel,
viscPanel,sphtPanel,spvolPanel,denPanel,spgrPanel; //$
  Unitt[] preUnits = new Unitt[6]; 
  Unitt[] tempUnits = new Unitt[4]; 
  Unitt[] mfractUnits = new Unitt[2]; 
  Unitt[] enthUnits = new Unitt[3]; 
  Unitt[] condUnits = new Unitt[4]; 
  Unitt[] viscUnits = new Unitt[4]; 
  Unitt[] sphtUnits = new Unitt[3]; 
  Unitt[] spvolUnits = new Unitt[2]; 
  Unitt[] denUnits = new Unitt[2]; 
  Unitt[] spgrUnits = new Unitt[1]; 

  public void init () { 

    // Pick Font for the Application 
    f1 = new Font("TimesRoman",Font.BOLD,10); 
    f2 = new Font("TimesRoman",Font.PLAIN,12); 
    f3 = new Font("Helvetica",Font.ITALIC,13); 
    f4 = new Font("Helvetica",Font.BOLD,12); 
    f5 = new Font("Helvetica",Font.PLAIN,9); 
    Color colw = new Color(255,255,255); 
    Color colc = new Color(0,255,255); 
    Color colg = new Color(0,255,0); 
    Color colr = new Color(255,0,0); 
    Color col2 = new Color(120,192,255); 
    Color col3 = new Color(255,122,122); 
    Color col4 = new Color(122,255,122); 
    setBackground(colc); 
    // First generate the GUI objects 
    pone = new Panel(); 
    pai = new Panel(); 
    pmr = new Panel(); 
    pse = new Panel(); 
    pcr = new Panel(); 
    pl = new Panel(); 
    pst = new Panel(); 
    pcc = new Panel(); 
    pupper = new Panel(); 
    plower = new Panel(); 
    pgo = new Panel(); 
    lmsg = new Label ("Message: ",0); 
    ltype = new Label ("Formulation:   ",0); 
    lsys = new Label ("Unit System:   ",0); 
    lme = new Label("Code: McNeely, Source: ASHRAE, Author: Gautam Chatur ",0); 
    lt = new Label("        "); 
  //  round = new TextField( "Please Enter the Parameters",170); 

    round = new TextArea("",3,100); 
//,TextArea.SCROLLBARS_VERTICAL_ONLY); 
    round.preferredSize(3,100); 
    round.setText("Please Enter the Parameters"); 
    round.setBackground(colw); 
    round.show(); 

    babout = new Button("     About     "); 
    binstru = new Button("Instructions"); 
    bclear = new Button("    Clear    ");    bcal = new Button( "  Calculate  "); 
    bg = new TextField("      -  ",1); 
    bg.preferredSize(1); 
    bg.setEditable(false); 
    br = new TextField("      o  ",1); 
    br.preferredSize(1); 
    br.setEditable(false); 
    bg.setBackground(Color.green); 
    bg.show(); 
    br.setBackground(Color.cyan); 
    br.show(); 
    bcal.setBackground(col2); 
    bcal.show(); 
    binstru.setBackground(col2); 
    binstru.show(); 
    babout.setBackground(col2); 
    babout.show(); 
    bclear.setBackground(col2); 
    bclear.show(); 
    cbSys = new CheckboxGroup(); 
    cbType = new CheckboxGroup(); 
    cbSys1 = new Checkbox("SI",cbSys,true); 
    cbSys2 = new Checkbox("English",cbSys,false); 
    cb1 = new Checkbox("Pressure"); 
    cb2 = new Checkbox("Temperature"); 
    cb3 = new Checkbox("Enthalpy"); 
    cb4 = new Checkbox("LiBr Mass Fraction"); 
    cb5 = new Checkbox(""); 
    cb6 = new Checkbox(""); 
    cb7 = new Checkbox(""); 
    cb8 = new Checkbox(""); 
    cb9 = new Checkbox(""); 
    cb10 = new Checkbox(""); 
  
    cbType1 = new Checkbox("McNeely",cbType,true); 
    cbType2 = new Checkbox("SSC2",cbType,false); 
    cbType3 = new Checkbox("SSC3",cbType,false); 

    preUnits[0] = new Unitt("kPa",1.0); 
    preUnits[1] = new Unitt("MPa",1000.0); 
    preUnits[2] = new Unitt("bar",100.0); 
    preUnits[3] = new Unitt("atm",101.325); 
    preUnits[4] = new Unitt("psi",6.8948); 
    preUnits[5] = new Unitt("mm of Hg",7.500615); 
    prePanel = new ConversionPanel(this,cb1,"",preUnits,1); 
  
    tempUnits[0] = new Unitt("degC",1); 
    tempUnits[1] = new Unitt("K",1); 
    tempUnits[2] = new Unitt("degF",1); 
    tempUnits[3] = new Unitt("degR",1); 
    tempPanel = new ConversionPanel(this,cb2,"",tempUnits,1); 
  
    enthUnits[0] = new Unitt("kJ/kg",1.0); 
    enthUnits[1] = new Unitt("cal/g",4.1868); 
    enthUnits[2] = new Unitt("Btu/lbm",2.326); 
    enthPanel = new ConversionPanel(this,cb3,"",enthUnits,1); 
  
    mfractUnits[0] = new Unitt("Percentage",1); 
    mfractUnits[1] = new Unitt("Fraction",0.01); 
    mfractPanel = new ConversionPanel(this,cb4,"",mfractUnits,1); 
  
    condUnits[0] = new Unitt("W/m.K",1.0); 
    condUnits[1] = new Unitt("Btu.in/s.ft^2.F",0.001925964); 
    condUnits[2] = new Unitt("Btu.in/h.ft^2.F",6.933472); 
    condUnits[3] = new Unitt("cal/cm.s.degC",0.000239005); 
    condPanel = new ConversionPanel(this,cb5,"Conductivity",condUnits,0); 
  
    viscUnits[0] = new Unitt("Pa.s",1.0); 
    viscUnits[1] = new Unitt("poise",10.0); 
    viscUnits[2] = new Unitt("centipoise",1000.0); 
    viscUnits[3] = new Unitt("lbf.s/ft^2",0.02088543); 
    viscPanel = new ConversionPanel(this,cb6,"Viscosity",viscUnits,0); 
  
    sphtUnits[0] = new Unitt("kJ/kg.K",1.0); 
    sphtUnits[1] = new Unitt("Btu/lbm.F",2.2); 
    sphtUnits[2] = new Unitt("cal/g.C",2.2); 
    sphtPanel = new ConversionPanel(this,cb7,"Sp. Heat",sphtUnits,0); 
    spvolUnits[0] = new Unitt("m^3/kg",1.0); 
    spvolUnits[1] = new Unitt("ft^3/lbm",2.2); 
    spvolPanel = new ConversionPanel(this,cb8,"Sp. Volume",spvolUnits,0); 

    denUnits[0] = new Unitt("kg/m^3",1.0); 
    denUnits[1] = new Unitt("lbm/ft^3",2.2); 
    denPanel = new ConversionPanel(this,cb9,"Density",denUnits,0); 
  
    spgrUnits[0] = new Unitt("Unitless",1.0); 
    spgrPanel = new ConversionPanel(this,cb10,"Sp. Gravity",spgrUnits,0); 
  
  
  
//    grollNew = new GrollNew(this,tempPanel.textField,"Temperature varies as per the value above"); 
  
    // Set the font on the GUI 
    round.setFont(f2); 
    lmsg.setFont(f4); 
    ltype.setFont(f4); 
    lme.setFont(f5); 
     lsys.setFont(f4); 
    babout.setFont(f4); 
    binstru.setFont(f4); 
    bclear.setFont(f4); 
    bcal.setFont(f4); 
    cbSys1.setFont(f1); 
    cbSys2.setFont(f1); 
    cbType1.setFont(f1); 
    cbType2.setFont(f1); 
    cbType3.setFont(f1); 
  
    // Resize the applet panel 
    resize(700,450); 
  
    //Layout for the Container 
     setLayout(new BorderLayout()); 
     pone.setLayout(new BorderLayout()); 
     pupper.setLayout(new GridLayout(2,2,5,5)); 
     plower.setLayout(new BorderLayout()); 
     pcr.setLayout(new GridLayout(1,4,2,2)); 
     pse.setLayout(new GridLayout(1,4,2,2)); 
     pgo.setLayout(new GridLayout(1,2,4,4)); 
     pai.setLayout(new GridLayout(1,4,6,6)); 
     pl.setLayout(new GridLayout(3,3,5,5)); 
     pst.setLayout(new GridLayout(1,5,5,5)); 
     minimumSize(); 

    // Now add the components 
    pai.add(babout); 
    pai.add(binstru); 
    pai.add(bclear); 
    pai.add(bcal); 
    pcr.add(ltype); 
    pcr.add(cbType1); 
    pcr.add(cbType2); 
    pcr.add(cbType3); 
    pse.add(lsys); 
    pse.add(cbSys1); 
    pse.add(cbSys2); 
    pgo.add(bg); 
    pgo.add(br); 
    pst.add(lt); 
    pst.add(lt); 
    pst.add(lt); 
    pst.add(lt); 
    pst.add(pgo); 
//    pse.add(pgo); 
    pupper.add(lme); 
    pupper.add(pst); 
    pupper.add(pcr); 
    pupper.add(pse); 
    //pupper.add(pq); 
    //pupper.add(pst); 
    add("North",pupper); 
     plower.add("North",lmsg); 
    plower.add("Center",round); 
    plower.add("South",pai); 

    pl.add(tempPanel); 
    pl.add(prePanel); 
    pl.add(mfractPanel); 
    pl.add(enthPanel); 
    pl.add(sphtPanel); 
    pl.add(spvolPanel); 
    pl.add(denPanel); 
   // pl.add(spgrPanel); 
    pl.add(condPanel); 
    pl.add(viscPanel); 
    //pone.add("Center",pl); 
    add("Center",pl); 
    add("South",plower); 
//   add(grollNew); 

    validate(); 
} 
 /** Draws a box around this panel. */ 
    public void paint(Graphics g) { 
        Dimension d = size(); 
        g.drawRect(0,0, d.width - 1, d.height - 1); 
    } 
    /** 
     * Puts a little breathing space between 
     * the panel and its contents, which lets us draw a box 
     * in the paint() method. 
     */ 
    public Insets pinsets() { 
        return new Insets(5,5,5,5); 
    } 

/** Temperature Routine 
*/ 

static double tsat(double p1, double x1){ 
    double c = 7.05; 
    double d = -1596.49; 
    double ee = -104095.5; 
    double a0 = -2.00755; 
    double a1 = 0.16976; 
    double a2 = -0.003133362; 
    double a3 = 0.0000197668; 
    double b0 = 124.937; 
    double b1 = -7.71649; 
    double b2 = 0.152286; 
    double b3 = -0.00079509; 
    double tsat; 
    try { 
    double suma = a0 + a1*x1 + a2*Math.pow(x1,2) + a3*Math.pow(x1,3); 
    double sumb = b0 + b1*x1 + b2*Math.pow(x1,2) + b3*Math.pow(x1,3); 
    double tp = -(2.0 * ee / (d + Math.pow(d * d - 4.0 * ee * ( c - 
Math.log(p1) / Math.log(10.0)),0.5))) - 273.15; 
    tsat = sumb + tp * suma; 
    } catch (java.lang.NumberFormatException e) { 
    tsat = 0.0; 
    } 
    return tsat; 
} 
/** Mass Fraction Routine 
*/ 
  
static double xsat(double t, double p){ 
    double x1 = 55; 
    double p1 = psat(x1,t); 
    int counter = 0; 
    while ( Math.abs(p1-p)>0.0001){ 
      counter = counter++; 
      double x2 = x1 + 0.001; 
      double p2 = psat(x2,t); 
      double dxdp = (x1-x2)/(p1-p2); 
      x1 = x1 + dxdp * (p - p1); 
      p1 = psat(x1,t); 
    } 
    return x1; 
} 

/** hsteam Routine 
*/ 
static double hsteam( double t1){ 
    double hsteam = 2593.9 + (t1 - 50) * 1.878; 
    return hsteam; 
} 
  

/**  Pressure Routine 
*/ 

static double psat(double x1,double t1){ 
    double a0 = -2.00755; 
    double a1 = 0.16976; 
    double a2 = -0.003133362; 
    double a3 = 0.0000197668; 
    double b0 = 124.937; 
    double b1 = -7.71649; 
    double b2 = 0.152286; 
    double b3 = -0.00079509; 
    double c = 7.05; 
    double d = -1596.49; 
    double ee = -104095.5; 
    double tpk,p1; 
    try { 
    double suma = a0 + a1 * x1 + a2 * Math.pow(x1,2) + a3 * 
Math.pow(x1,3); 
    double sumb = b0 + b1 * x1 + b2 * Math.pow(x1,2) + b3 * 
Math.pow(x1,3); 
    double tp = (t1 - sumb)/suma; 
    tpk = tp +273.15; 
    } catch (java.lang.NumberFormatException e) { 
    tpk = 0.0; 
    } 
    p1 = Math.pow(10,(c + d / tpk + ee / (Math.pow(tpk,2)))); 
    return p1; 
} 
  
/** enth routine 
*/ 

static double enth(double t1,double x1){ 
    double ah0 = -2024.33; 
    double ah1 = 163.309; 
    double ah2 = -4.88161; 
    double ah3 = 0.06302948; 
    double ah4 = -0.0002913705; 
    double bh0 = 18.2829; 
    double bh1 = -1.1691757; 
    double bh2 = 0.03248184; 
    double bh3 = -0.0004034184; 
    double bh4 = 0.0000018520569; 
    double ch0 = -0.037008214; 
    double ch1 = 0.0028877666; 
    double ch2 = -0.000081313015; 
    double ch3 = 0.00000099116628; 
    double ch4 = -4.4441207e-09; 
    double tt1 = t1; 
    double f; 
    double xx1 = x1; 
    try { 
    double suma = ah0 + ah1 * xx1 + ah2 * Math.pow(xx1,2) + ah3 * 
Math.pow(xx1,3) + ah4 * Math.pow(xx1,4); 
    double sumb = bh0 + bh1 * xx1 + bh2 * Math.pow(xx1,2) + bh3 * 
Math.pow(xx1,3) + bh4 * Math.pow(xx1,4); 
    double sumc = ch0 + ch1 * xx1 + ch2 * Math.pow(xx1,2) + ch3 * 
Math.pow(xx1,3) + ch4 * Math.pow(xx1,4); 
    f = suma + sumb * tt1 + sumc * Math.pow(tt1,2); 
   } catch (java.lang.NumberFormatException e) { 
    f = 10.0; 
    } 
    return f; 
} 
/** Conductivity Routine 
*/ 
static double cond(double t,double x) { 
    t = t + 273.15; 
    x = x/100; 
    double a0 = -0.88045; 
    double a1 = 0.883985; 
    double b0 = 0.0089866; 
    double b1 = -0.0076652; 
    double c0 = -0.000015543; 
    double c1 = 0.000013887; 
    double d0 = 0.0000000073203; 
    double d1 = -0.0000000063195; 
    double sum1,sum2,cond; 
    try { 
        sum1 = a0 + a1 * x + (b0 + b1 * x) * t; 
        sum2 = (c0 + c1 * x) * t * t + (d0 + d1 * x) * t * t * t; 
        cond = sum1 + sum2; 
    } catch (java.lang.NumberFormatException e) { 
        cond = 0.0; 
    } 
    return cond; 
} 
/** Viscosity Routine 
*/ 
static double visc(double t,double x) { 
    t = t + 273.15; 
    x = x /100; 
    double a0 = -2.321264167; 
    double a1 = 3.190587778; 
    double b0 = -609.4495716; 
    double b1 = 963.1637016; 
    double c0 = 372994.8558; 
    double c1 = -35211.99699; 
    double visc; 
    try { 
        visc = Math.exp(a0 + a1 * x * x + (b0 + b1 * x * x) / t + (c0 + c1 
* x * x) / (t * t)); 
        //System.out.println("hi" +visc); 
    } catch(java.lang.NumberFormatException e) { 
        visc = 0.0; 
    } 
    visc = visc /1000; 
    return visc; 
} 
  
/** Specific Heat Routine 
*/ 

static double spheat(double t,double x) { 
   double dt = 0.0001; 
   double tp = t + dt/2.0; 
   double tm = t - dt/2.0; 
   double dhdt; 
   try { 
       double hp = enth(tp,x); 
       double hm = enth(tm,x); 
       dhdt = (hp - hm)/dt; 
   } catch(java.lang.NumberFormatException e) { 
       dhdt = 0.0; 
   } 
   return dhdt; 
   } 

/** Draws a box around this panel. */ 
/* 
public void paint(Graphics g) { 
    int[] eP = new int[12]; 
    int[] xP = {0,10,20,30,35,40,45,50,55,60,65,70}; 
    double[] xxP = 
{0.0,10.0,20.0,30.0,35.0,40.0,45.0,50.0,55.0,60.0,65.0,70.0}; 
    int pts = 12; 
    double dd; 
    String ss; 
    for(int i = 0; i<eP.length ; i++){ 
        dd = 
enth((Double.valueOf(tempPanel.textField.getText()).doubleValue()),xxP[i]); 
        ss = Double.toString(dd); 
        eP[i] = Double.valueOf(ss).intValue(); 
     } 
    Dimension d = size(); 
    setBackground(Color.white); 
    g.drawRect(0,0, d.width - 1, d.height - 1); 
    g.drawPolyline(xP,eP,pts); 
} 
*/ 
  
  

/** 
 * Puts a little breathing space between 
 * the panel and its contents, which les us draw a box 
 * in the paint() method. 
 */ 

public Insets insets() { 
    return new Insets(5,5,5,5); 
} 
  
/** Check the number of checkboxes which are checked */ 
  
public int  Checksum(){ 
    int i,j,k,l; 
    i = (cb1.getState()?1:0); 
    j = (cb2.getState()?1:0); 
    k = (cb3.getState()?1:0); 
    l = (cb4.getState()?1:0); 
    return(i+j+k+l); 
} 

/** Give Message as per the number of Boxes checked */ 

public void verify(Checkbox c1){ 
    int resp = Checksum(); 
    if ( resp <2) 
       round.setText(" A minimum of two parameters have to be entered.\n  Please check one more box"); 
    else if (resp == 2) 
       round.setText(" Please input the values. \n Then press calculate to find the solution"); 
    else if (resp > 2){ 
       round.setText(" Only two parameters can be entered. \n Please deselect one box and re-select the boxes"); 
       c1.setState(false); 
    } 
  
} 
  
/** Respond to the slider. */ 
/* 
public boolean handleEvent(Event e) { 
    if (e.target instanceof Scrollbar) { 
        if (cb2.getState() == false){ 
            showStatus("Please select the check box for temperature"); 
            slider.setSliderValue(getValue()); 

        } else{ 
            showStatus("Value of Temperature changes.."); 
            round.setText("Change temperature"); 
           tempPanel.setText(String.valueOf(slider.getValue())); 
        } 
    } 
        return super.handleEvent(e); 
} 
*/ 
/* Action to be taken when mouse/box is clicked */ 
  
public boolean action(Event e, Object o){ 
    int i = 0; 
    Color colw = new Color(255,255,255); 
    Color colc = new Color(0,255,255); 
    if( e.target instanceof Checkbox) { 
        if( e.target == cb1){ 
            verify(cb1); 
            if (cb1.getState()==true){ 
                prePanel.textField.setBackground(colw); 
                prePanel.textField.show(); 
                prePanel.textField.setEditable(true); 
            } else{ 
                prePanel.textField.setBackground(colc); 
                prePanel.textField.show(); 
                prePanel.textField.setText("0"); 
                prePanel.textField.setEditable(false); 
            } 
        } 
        if( e.target == cb2){ 
            verify(cb2); 
            if (cb2.getState()==true){ 
                 tempPanel.textField.setBackground(Color.white); 
                 tempPanel.textField.show(); 
                 tempPanel.textField.setEditable(true); 
            } else{ 
                 tempPanel.textField.setBackground(Color.cyan); 
                 tempPanel.textField.show(); 
                 tempPanel.textField.setText("0"); 
                 tempPanel.textField.setEditable(false); 
            } 
        } 
        if( e.target == cb3){ 
            verify(cb3); 
            if (cb3.getState()==true){ 
                 enthPanel.textField.setBackground(colw); 
                 enthPanel.textField.show(); 
                 enthPanel.textField.setEditable(true); 
                 enthPanel.textField.setEditable(true); 
            } else { 
                 enthPanel.textField.setBackground(colc); 
                 enthPanel.textField.setBackground(colc); 
                 enthPanel.textField.setText("0"); 
                 enthPanel.textField.setEditable(false); 
            } 
        } 
        if( e.target == cb4){ 
            verify(cb4); 
            if (cb4.getState()==true){ 
                 mfractPanel.textField.setBackground(colw); 
                 mfractPanel.textField.show(); 
                 mfractPanel.textField.setEditable(true); 
            } else{ 
                 mfractPanel.textField.setBackground(colc); 
                 mfractPanel.textField.show(); 
                 mfractPanel.textField.setText("0"); 
                 mfractPanel.textField.setEditable(false); 
            } 
         } 
         if(e.target == cbSys2){ 
             prePanel.unitChooser.select(4); 
             enthPanel.unitChooser.select(2); 
             tempPanel.unitChooser.select(2); 
             condPanel.unitChooser.select(2); 
             viscPanel.unitChooser.select(3); 
             sphtPanel.unitChooser.select(1); 
             spvolPanel.unitChooser.select(1); 
             denPanel.unitChooser.select(1); 
         } 
         if(e.target == cbSys1){ 
             prePanel.unitChooser.select(0); 
             enthPanel.unitChooser.select(0); 
             tempPanel.unitChooser.select(0); 
             condPanel.unitChooser.select(0); 
             viscPanel.unitChooser.select(0); 
             sphtPanel.unitChooser.select(0); 
             spvolPanel.unitChooser.select(0); 
             denPanel.unitChooser.select(0); 
        } 
    } 
    if( e.target instanceof Button) { 
        f2 = new Font("TimesRoman",Font.PLAIN,12); 
        round.setFont(f2); 
        if(e.target == babout) { 
            showStatus("About"); 
            f3 = new Font("Helvetica",Font.BOLD,13); 
            round.setText(" "); 
            round.setFont(f3); 
   round.setText("                 Sorption Systems Consortium \n Aqueous Lithium Bromide Properties \n          Center for Environmental Energy Engineering \n            University of Maryland at College Park"); 
        } 
        if(e.target == binstru) { 
            showStatus("Instructions"); 
            round.setText("Please check any two Checkboxes.\n Enter the values and then press calculate."); 
        } 
        if(e.target == bclear) { 
            showStatus("Clear"); 
            round.setText("Clear..."); 
            tempPanel.textField.setText("0"); 
            prePanel.textField.setText("0"); 
            mfractPanel.textField.setText("0"); 
            enthPanel.textField.setText("0"); 
            condPanel.textField.setText("0"); 
            viscPanel.textField.setText("0"); 
             sphtPanel.textField.setText("0"); 
             spvolPanel.textField.setText("0"); 
             denPanel.textField.setText("0"); 
         } 
        if(e.target == bcal){ 
            if(Checksum() != 2 ) { 
                round.setText("A minimum of two parameters have to be entered.\n Please select two checkboxes, and then enter the parameters"); 
  
            } else { 
            if (cbType1.getState() == true ) { 
            showStatus("Calculating, be patient"); 
            round.setText("Calculating..."); 
            spvolPanel.textField.setText("N.A."); 
            bg.setBackground(Color.cyan); 
            br.setBackground(Color.red); 
            bg.show(); 
            br.show(); 
        if((cb1.getState() == true) && (cb2.getState() == true)){ 
            double p = 
((Double.valueOf(prePanel.textField.getText()).doubleValue())/prePanel.getMultiplier() ); //$ 
            double t = 
(Double.valueOf(tempPanel.textField.getText()).doubleValue()); 
  
            int ti = tempPanel.unitChooser.getSelectedIndex(); 
            if ( ti == 1 ) { t = t - 273.15; }                  //K to c 
            if ( ti == 2 ) { t = (5.0/9.0)*(t - 32.0); }        //F to c 
            if ( ti == 3 ) { t = (5.0/9.0)*t - 273.15; }        //R to c 
  
            if (( p >= 0.0 ) && ( p <= 3e3 ) && ( t >= 0.0 ) && ( t <= 
180.0 )) { 
                double x = xsat(t,p); 
  
mfractPanel.textField.setText(String.valueOf(x*mfractPanel.getMultiplier())); 
                double spht = spheat(t,x); 
  
sphtPanel.textField.setText(String.valueOf(spht*sphtPanel.getMultiplier())); 
                double h = enth(t,x); 
  
enthPanel.textField.setText(String.valueOf(h*enthPanel.getMultiplier())); 
                double co = cond(t,x); 
  
condPanel.textField.setText(String.valueOf(co*condPanel.getMultiplier())); 
                double vi = visc(t,x); 
  
viscPanel.textField.setText(String.valueOf(vi*viscPanel.getMultiplier())); 
                double spht1 = spheat(t,x); 
  
sphtPanel.textField.setText(String.valueOf(spht1*sphtPanel.getMultiplier())); 
  
            } else { 
                round.setText("Parameters not in the specified range"); 
                showStatus("Please reenter parameters"); 
                i = 1; 
                enthPanel.textField.setText("0"); 
                mfractPanel.textField.setText("0"); 
               condPanel.textField.setText("0"); 
                viscPanel.textField.setText("0"); 
                sphtPanel.textField.setText("0"); 
            } 
        } 

        if((cb2.getState() == true) && (cb4.getState() == true)){ 

            double t = 
(Double.valueOf(tempPanel.textField.getText()).doubleValue()); 
            double x = (Double.valueOf(mfractPanel.textField.getText()).doubleValue())/mfractPanel.getMultiplier(); //$ 
            int ti = tempPanel.unitChooser.getSelectedIndex(); 
            if ( ti == 1 ) { t = t - 273.15; }           //K to c 
            if ( ti == 2 ) { t = (5.0/9.0)*( t - 32.0); }//F to c 
            if ( ti == 3 ) { t = (5.0/9.0)*t - 273.15; } //R to c 
  
            if (( x >= 40.0 ) && ( x <= 75.0 ) && ( t >= 0.0 ) && ( t <= 
180.0 )) { 
                double spht = spheat(t,x); 
  
sphtPanel.textField.setText(String.valueOf(spht*sphtPanel.getMultiplier())); 
                double p = psat(x,t); 
  
prePanel.textField.setText(String.valueOf(p*prePanel.getMultiplier())); 
                double h = enth(t,x); 
  
enthPanel.textField.setText(String.valueOf(h*enthPanel.getMultiplier())); 
                double co = cond(t,x); 
  
condPanel.textField.setText(String.valueOf(co*condPanel.getMultiplier())); 
                double vi = visc(t,x); 
  
viscPanel.textField.setText(String.valueOf(vi*viscPanel.getMultiplier())); 
  
            } else { 
                round.setText("Parameters not in the specified range"); 
                showStatus("Please reenter parameters"); 
                i = 1; 
                enthPanel.textField.setText("0"); 
                prePanel.textField.setText("0"); 
                condPanel.textField.setText("0"); 
                viscPanel.textField.setText("0"); 
                sphtPanel.textField.setText("0"); 
            } 
        } 
        if((cb1.getState() == true) && (cb4.getState() == true)){ 
            double p = 
((Double.valueOf(prePanel.textField.getText()).doubleValue())/prePanel.getMultiplier() ); //$ 
            double x = 
(Double.valueOf(mfractPanel.textField.getText()).doubleValue())/mfractPanel.getMultiplier(); //$ 
  
            if (( p >= 0.0 ) && ( p <= 3e3 ) && ( x >= 40.0 ) && ( x <= 
75.0 )) { 
                double t = tsat(p,x); 
                double h = enth(t,x); 
  
enthPanel.textField.setText(String.valueOf(h*enthPanel.getMultiplier())); 
                double co = cond(t,x); 

condPanel.textField.setText(String.valueOf(co*condPanel.getMultiplier())); 
                double vi = visc(t,x); 

viscPanel.textField.setText(String.valueOf(vi*viscPanel.getMultiplier())); 
                double spht1 = spheat(t,x); 

sphtPanel.textField.setText(String.valueOf(spht1*sphtPanel.getMultiplier()));  //$
                int ti = tempPanel.unitChooser.getSelectedIndex(); 
                if ( ti == 1 ) { t = t + 273.15; }                   //c to K 
                if ( ti == 2 ) { t = (9.0/5.0) * t  + 32.0; }      //c to F 
                if ( ti == 3 ) { t = (t + 273.15) * (9.0/5.0); }     //c to R 
                tempPanel.textField.setText(String.valueOf(t)); 
             } else { 
                round.setText("Parameters not in the specified range"); 
                showStatus("Please reenter parameters"); 
                i = 1; 
                enthPanel.textField.setText("0"); 
                tempPanel.textField.setText("0"); 
                condPanel.textField.setText("0"); 
                viscPanel.textField.setText("0"); 
                sphtPanel.textField.setText("0"); 
                } 
        } 
        if((Checksum() == 2) && (cb3.getState() == true)){ 
            round.setText("Valid combinations are T-p,p-x,T-x"); 
            showStatus("Re-enter combination.."); 
        } else{ 
            if (i == 0 ) { 
                showStatus("Calculated Values are"); 
                round.setText("Calculated..."); 
                bg.setBackground(Color.green); 
                br.setBackground(Color.cyan); 
                bg.show(); 
                br.show(); 
            } 
        } 
        }else { 
        round.setText(" SSC2 and SSC3 formulations are available only to registered CEEE users. \n For more information please contact CEEE"); 
        } 
        } 
      return true; 
    } 
    return true; 
} 
return true; 
} 
} 
  
/** About */ 
/* 
class About extends Frame { 
    Button okButton; 
    Graphics g; 
  
    public static void main(String args[]){ 
        System.out.println("About"); 
        About ab = new About(); 
    } 
  
    public About() { 
        setTitle("About"); 
  
        setLayout( new FlowLayout()); 
        okButton = new Button("OK"); 
        add(okButton); 
  
        resize(300,300); 
        show(); 
  
        g = getGraphics(); 
        paint(g); 
    } 
    public void paint(Graphics g) { 
        g.drawString("This is about.....",10,10); 
        g.drawRect(20,20,150,200); 
    } 
} 
*/ 
/** GrollNew Class */ 
  
class GrollNew extends Panel{ 
  
    TextField which; 
    win1 controller1; 
    String comment; 
    //graph g1; 
    int min = 0; 
    int max = 180; 
    Scrollbar slider; 

GrollNew (win1 mycontroller1,TextField mywhich,String mycomment){ 
    GridBagConstraints cc = new GridBagConstraints(); 
    GridBagLayout gridbag = new GridBagLayout(); 
    setLayout(gridbag); 
    controller1 = mycontroller1; 
    which = mywhich; 
    comment = mycomment; 
    cc.fill = GridBagConstraints.HORIZONTAL; 
    Label label = new Label(mycomment,Label.CENTER); 
    cc.gridwidth = GridBagConstraints.REMAINDER; 
    gridbag.setConstraints(label,cc); 
    //graph g1 = new graph(which); 
    add(label); 
    slider = new Scrollbar(Scrollbar.HORIZONTAL,0,10,min,max); 
    cc.gridwidth = 1; 
    gridbag.setConstraints(slider,cc); 
    add(slider); 
} 
  
public void paint(Graphics gg,int[] xP,int[] eP,int pts){ 
    gg.drawRect(0,0,100,100); 
    gg.drawPolyline(xP,eP,pts); 
} 
  
/** 
 * Gets the current value in the text field. 
 * That's guaranteed to be the same as the value 
 * in the scroller (subject to rounding, of course). 
 */ 
double getValue() { 
    double f; 
    try  { 
        f = Double.valueOf(which.getText()).doubleValue(); 
    } catch (java.lang.NumberFormatException e) { 
        f = 0.0; 
    } 
        return f; 
} 
  
/** Respond to user actions on controls. */ 
public boolean action(Event e, Object arg) { 
        if (e.target instanceof TextField) { 
            setSliderValue(getValue()); 
            //controller.convert(this); 
            return true; 
        } 
//        if (e.target instanceof Choice) { 
            //win1.convert(this); 
 //           return true; 
  //      } 
        return false; 
} 
public boolean handleEvent(Event e) { 
      setSliderValue(getValue()); 
  
     if (e.target instanceof Scrollbar) { 
        if (controller1.cb2.getState() != true ){ 
            controller1.showStatus("Please select the check box for temperature"); 
            setSliderValue(getValue()); 
            System.out.println("Check1"); 
  
        } else{ 
            controller1.showStatus("Value of Temperature changes.."); 
            controller1.round.setText("Change temperature"); 
            which.setText(String.valueOf(slider.getValue())); 
        } 
    } 
        return super.handleEvent(e); 
} 
  
  
/** Set the values in the slider and text field. */ 
void setValue(double f) { 
    setSliderValue(f); 
    which.setText(String.valueOf(f)); 
} 
  
/** Set the slider value. */ 
void setSliderValue(double f) { 
    int sliderValue = (int)f; 
  
    if (sliderValue > max) 
          sliderValue = max; 
    if (sliderValue < min) 
          sliderValue = min; 
          slider.setValue(sliderValue); 
    } 
  
/** Draws a box around this panel. */ 
  
public void paint(Graphics g) { 
     Dimension d = size(); 
     g.drawRect(0,0, d.width - 1, d.height - 1); 
} 
  
/** 
 * Puts a little breathing space between 
 * the panel and its contents, which lets us draw a box 
 * in the paint() method. 
 */ 
public Insets insets() { 
    return new Insets(5,5,5,5); 
} 
} 
  
  
/** Conversion Panel Class */ 
  
class ConversionPanel extends Panel{ 
    TextField textField; 
    Choice unitChooser; 
    win1 controller; 
    Unitt[] units; 
    Checkbox cb; 
    int check; 
    ConversionPanel (win1 myController,Checkbox mycb,String 
myTitle,Unitt[] myUnits, int chk){ 
    //Initialize this ConversionPanel to use a GridBagLayout. 
    GridBagConstraints c = new GridBagConstraints(); 
    GridBagLayout gridbag = new GridBagLayout(); 
    setLayout(gridbag); 
  
    //Save arguments in instance variables. 
    controller = myController; 
    units = myUnits; 
    cb = mycb; 
    check = chk; 
  
    //Set up default layout constraints. 
    c.fill = GridBagConstraints.HORIZONTAL; 
  
    //Add the label.  It displays this panel's title, centered. 
    Label label = new Label(myTitle, Label.CENTER); 
    c.gridwidth = GridBagConstraints.REMAINDER; //It ends a row. 
    gridbag.setConstraints(label, c); 
    gridbag.setConstraints(cb, c); 
    if ( chk == 1 ) { 
    add(cb); 
    } 
    if (chk == 0 ) { 
    add(label); 
    } 
    //Add the text field.  It initially displays "0" and needs 
    //to be at least 10 columns wide. 
    textField = new TextField("0", 10); 
    textField.setEditable(false); 
    c.weightx = 1.0;  //This component should use all available horizontal space. 
    c.gridwidth = 1; //The default value. 
    gridbag.setConstraints(textField, c); 
    Font fu = new Font("Helvetica",Font.PLAIN,11); 
    Font ft = new Font("Helvetica",Font.PLAIN,13); 
    textField.setFont(ft); 
    add(textField); 
  
    //Add the pop-up list (Choice). 
    unitChooser = new Choice(); 
    for (int i = 0; i < units.length; i++) { //Populate it. 
        unitChooser.addItem(units[i].description); 
    } 
        c.weightx = 0.0; //The default value. 
        c.gridwidth = GridBagConstraints.REMAINDER; //End a row. 
        gridbag.setConstraints(unitChooser, c); 
        unitChooser.setFont(fu); 
        //unitChooser.setColor(controller.col4); 
         add(unitChooser); 
} 
  
  
/** 
 * Returns the multiplier (units/meter) for the currently 
 * selected unit of measurement 
 */ 
  
double getMultiplier() { 
    int i = unitChooser.getSelectedIndex(); 
    return (units[i].multiplier); 
} 
  
/** Draws a box around this panel. */ 
public void paint(Graphics g) { 
    Dimension d = size(); 
    g.drawRect(0,0, d.width - 1, d.height - 1); 
} 
  
  
/** 
 * Puts a little breathing space between 
 * the panel and its contents, which lets us draw a box 
 * in the paint() method. 
 */ 
public Insets insets() { 
   return new Insets(5,5,5,5); 
} 
} 
  

class Unitt{ 
    String description; 
    double multiplier; 
    Unitt(String description, double multiplier){ 
        super(); 
        this.description=description; 
        this.multiplier=multiplier; 
    } 
    public String toString(){ 
        String s = "Meters /"+description+"="+multiplier; 
        return s; 
    } 
} 
  
