import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.Locale;
import java.text.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.table.*;

public class girdiP3 extends JPanel implements ActionListener,ItemListener,Serializable
{
  String gas[];
  double ngas[];
  double Tgas[];
  double Tegas;
  double Pegas;
  int n1;
  JPanel p1,p2,p3,p4,p;
  JLabel l1[];           // Label prompt unit
  JLabel l2[];           // Label prompt unit
  JTextField t1[];
  JComboBox c2[];
  JTextField t2[];
  JTextField t3[];
  JLabel jl[];

  double a[];

  JLabel heading;
  //JButton jb;
  int n;

  
  public girdiP3(String g1[],double gn1[],double gT1[],double Tegasi,double Pegasi,String hh)
  { 
	Gas1 g=new Gas1("ch4");
	gas=new String[g1.length];
	ngas=new double[gn1.length];
	Tgas=new double[gn1.length];
	Tegas=Tegasi;
	Pegas=Pegasi;
    n1=g1.length;
    String baslik[]={"gazın ismi","gazın giriş mol miktarı","gazın giriş sıcaklığı derece K"};
	jl=new JLabel[7];
	jl[0]=new JLabel(baslik[0]);
	jl[1]=new JLabel(baslik[1]);
	jl[2]=new JLabel(baslik[2]);
	jl[3]=new JLabel("gazın çıkış sıcaklığı : ");
	jl[4]=new JLabel("derece K ");
	jl[5]=new JLabel("gazın çıkış basıncı : ");
	jl[6]=new JLabel("bar ");
	
    StringTokenizer token=new StringTokenizer(g.readGasNames());
    String st[]=new String[token.countTokens()];
    int i=0;
    while(token.hasMoreTokens())
    {
    st[i++]=new String((String)token.nextToken());
    }
    n=g1.length;
    l1=new JLabel[n];
    l2=new JLabel[n];
    t1=new JTextField[n+2];
    a=new double[n];
    heading=new JLabel(hh);
    p1=new JPanel();
    p2=new JPanel();
    p3=new JPanel();
    p4=new JPanel();
    p4.setLayout(new GridLayout(n+3,3,5,5)); 
    c2=new JComboBox[n];
    t2=new JTextField[n+2];
    t3=new JTextField[n];  
    p4.add(jl[0]);
    p4.add(jl[1]);
    p4.add(jl[2]);
    for(int iz=0;iz<n1;iz++)
    { gas[iz]=g1[iz];
      ngas[iz]=gn1[iz];
      Tgas[iz]=gT1[iz];
	  c2[iz]=new JComboBox(st);
	  t2[iz]=new JTextField(ngas[iz]+"              ");
      t3[iz]=new JTextField(Tgas[iz]+"              ");
	  t2[iz].setFont(new Font("TimesRoman",Font.BOLD,14));
	  t3[iz].setFont(new Font("TimesRoman",Font.BOLD,14));
      c2[iz].setSelectedItem(gas[iz]);
      t2[iz].addActionListener(this);
	  p4.add(c2[iz]);
	  p4.add(t2[iz]);
	  p4.add(t3[iz]);	  
      c2[iz].addItemListener(this);
      t2[iz].addActionListener(this);
      t3[iz].addActionListener(this);
    }
    t2[n]=new JTextField(Tegas+"              ");
    t2[n+1]=new JTextField(Pegas+"            ");
    p4.add(jl[3]);
    p4.add(t2[n]);
    p4.add(jl[4]);
    
    p4.add(jl[5]);
    p4.add(t2[n+1]);
    p4.add(jl[6]);
    
    t2[n].addActionListener(this);
    t2[n+1].addActionListener(this);
       p=new JPanel()
       {
        public Dimension getPrefferedSize()
        {
            Dimension size=super.getPreferredSize();
            size.width=200;
            size.height=100;
            return size;
        }
        };  
        p.add(p4,BorderLayout.NORTH);
	add(p);
  }
    
  public void actionPerformed( ActionEvent e)
  {
  int i=0;
  for(i=0;i<n;i++)
  {	if(e.getSource()==t2[i])
    { ngas[i]=Double.parseDouble(t2[i].getText());
      break;
    }
    else if(e.getSource()==t3[i])
    { Tgas[i]=Double.parseDouble(t3[i].getText());
      break;
    }
  }
  if(e.getSource()==t2[n])
    { Tegas=Double.parseDouble(t2[n].getText());
    }
  else if(e.getSource()==t2[n+1])
    { Pegas=Double.parseDouble(t2[n+1].getText());}
  repaint();
  }
  
  public void itemStateChanged(ItemEvent ev)
  {
  for(int i=0;i<n1;i++)
  {	if(ev.getSource()==c2[i])
    { gas[i]=(String)c2[i].getSelectedItem();break;}
  }
  }
      
  public double[] readNgas()
  {return ngas;}
  
  public double[] readTgas()
  {return ngas;}
  
  public String[] readgas()
  {return gas;}
  
 }

