//======================================================
// Numerical Analysis package in java
// GmixProperty class to calculate propertes of gas mixtures
// user interface (applet)
// Dr. Turhan Coban
// =====================================================
import java.io.*;
import Gmix;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.Border;

public class JGmixProperty extends JApplet implements ActionListener
{
  JLabel promptGmixName;         // Label prompt GmixName
  JLabel promptTemperature;      // Label prompt Temperature
  JLabel promptPressure;         // Label prompt Pressure
  JTextField inputGmixName;      // input GmixName
  JTextField inputTemperature;   // input Temperature
  JTextField inputPressure;      // input Pressure
  double T;
  double P;
  String GmixName;
  Gmix g1;
  File gmixFile;
  public void init()
  {
    //adding max-min prompts and input fields
    GmixName="air";
    try{
       g1=new Gmix(GmixName);
       } catch(IOException ioe) {System.out.println("IOException");}
    promptGmixName=    new JLabel("         Simple Gmix Name ");
    inputGmixName=new JTextField(20);
    promptTemperature=new JLabel("         Temperature (øC) : ");
    inputTemperature=new JTextField(20);
    promptPressure=   new JLabel("         Pressure (Bars)  :  ");
    inputPressure=new JTextField(20);
    T=27.0;
    P=1.0;
    inputGmixName.addActionListener(this);
    inputTemperature.addActionListener(this);
    inputPressure.addActionListener(this);
    JPanel pane= new JPanel();
    pane.add(promptGmixName);
    pane.add(inputGmixName);
    pane.add(promptTemperature);
    pane.add(inputTemperature);
    pane.add(promptPressure);
    pane.add(inputPressure);
    getContentPane().add(pane,BorderLayout.CENTER);
  }

  public void paintComponent(Graphics g)
  {
    super.paintComponent(g);
    double TK=T+273.0;
    inputGmixName.setText(GmixName.toString());
    inputTemperature.setText(Double.toString(T));
    inputPressure.setText(Double.toString(P));
    g.drawString("see Gmix.dat for available Gas mixture names: ",20,100);
    g.drawString(g1.toString("formula"),20,115);
    g.drawString(g1.toString("composition"),20,130);
    g.drawString("M                        kg/kmol  : ",20,150);
    g.drawString(""+g1.M,250,150);
    g.drawString("h, enthalpy              KJ/kmol  : ",20,165);
    g.drawString(Double.toString(g1.h(TK)),250,165);
    g.drawString("u, Internal energy       KJ/kmol  : ",20,180);
    g.drawString(Double.toString(g1.u(TK)),250,180);
    g.drawString("s, Entropy               KJ/kmol K: ",20,195);
    g.drawString(Double.toString(g1.s(TK,P)),250,195);
    g.drawString("v, Specific volume       m^3/kmol : ",20,210);
    g.drawString(Double.toString(g1.v(TK,P)),250,210);
    g.drawString("k, Thermal conductivity  W/m K    : ",20,225);
    g.drawString(Double.toString(g1.k(TK)),250,225);
    g.drawString("h+hf, ent + form. enth. KJ/kmol : ",20,240);
    g.drawString(Double.toString(g1.ht(TK)),250,240);
    g.drawString("Density   kg/m^3                  : ",20,255);
    g.drawString(Double.toString(g1.M/g1.v(TK,P)),250,255);
    g.drawString("Cp                      KJ/kmol K : ",20,270);
    g.drawString(Double.toString(g1.Cp(TK)),250,270);
    g.drawString("Cv                      KJ/kmol K : ",20,285);
    g.drawString(Double.toString(g1.Cv(TK)),250,285);
    g.drawString("Cp/Cv adiabatic constant          : ",20,300);
    g.drawString(Double.toString(g1.gamma(TK)),250,300);
    g.drawString("c speed of sound m/s              : ",20,315);
    g.drawString(Double.toString(g1.c(TK)),250,315);
    g.drawString("Viscosity                N s/m^2  : ",20,330);
    g.drawString(Double.toString(g1.vis(TK)),250,330);
    g.drawString("Pr,Prandtl Number                 : ",20,345);
    g.drawString(Double.toString(g1.Pr(TK)),250,345);
    }//end of method

public void actionPerformed( ActionEvent e)
{
  GmixName=inputGmixName.getText();
  try{
  g1=new Gmix(GmixName);
  } catch(IOException ioe1) {System.out.println("IOException");}
  Double valTemp=new Double(inputTemperature.getText());
  T=valTemp.doubleValue();
  Double valPressure=new Double(inputPressure.getText());
  P=valPressure.doubleValue();
  repaint();
}

}



