// ====================================================== // Thermodynamics package in java // gazTable class to calculate properties of gases // user interface (JFrame) // Dr. Turhan Coban // TUBITAK Marmara Research Center // Energy Systems and Environmental Research Institute // email : Turhan.Coban@posta.mam.gov.tr // ===================================================== import java.io.*; import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.table.*; public class idealgazTablosu extends JApplet implements ActionListener,ItemListener,Serializable { String s1[]={"SI","EN"}; String s2[]={"molar","kütle"}; String unit; String base; JPanel inputPanel; JPanel outputPanel; JPanel totalPanel; JLabel l1[]=new JLabel[5]; // Label JLabel l2[]=new JLabel[5]; // Label JTextField t1[]=new JTextField[3]; // input fields JComboBox c1[]=new JComboBox[3]; // selection field JTextArea outputTextArea; idealgazModeli gm; public gaz g1; JTable jt; double T; double P; public String gasName; protected File gmixFile; protected StringTokenizer token; String st[]; Color bg; Color fg; public void init() { Container c=getContentPane(); c.setLayout(new FlowLayout()); bg=c.getBackground(); fg=c.getForeground(); //adding max-min prompts and input fields gasName=new String("hava"); unit="SI"; base="mole"; T=27.0; P=1.0; inputPanel=new JPanel(); inputPanel.setLayout(new GridLayout(5,3,80,1)); outputPanel=new JPanel(); outputPanel.setLayout(new BorderLayout()); totalPanel=new JPanel(); totalPanel.setLayout(new BorderLayout()); c1[0]=new JComboBox(s1); c1[1]=new JComboBox(s2); g1=new gaz(gasName); token=new StringTokenizer(g1.readGasNames()); st=new String[token.countTokens()]; int i=0; while(token.hasMoreTokens()) { st[i++]=new String((String)token.nextToken()); } c1[2]=new JComboBox(st); t1[0] = new JTextField(); t1[1] = new JTextField(); t1[2] = new JTextField(); t1[2].setText(gasName); gasName=(String)c1[2].getSelectedItem(); g1=new gaz(gasName); l1[0]=new JLabel("birim sistemi "); fg=l1[0].getForeground(); l1[1]=new JLabel("kütle/molar "); l1[2]=new JLabel("gaz ismi "); l1[3]=new JLabel("sıcaklık "); l1[4]=new JLabel("basınç "); l2[0]=new JLabel(" "); l2[1]=new JLabel(" "); l2[2]=new JLabel(" "); l2[3]=new JLabel(" derece C "); l2[4]=new JLabel(" bar "); outputTextArea=new JTextArea(); Font fn=l1[0].getFont(); for(i=0;i<5;i++) { l1[i].setBackground(Color.lightGray); l2[i].setBackground(Color.lightGray); } t1[0]=new JTextField(""+T); t1[1]=new JTextField(""+P); for(i=0;i<3;i++) { t1[i].setBackground(bg);t1[i].setFont(fn); } for(i=0;i<3;i++) { c1[i].setBackground(bg);t1[i].setFont(fn); } outputTextArea.setBackground(bg); outputTextArea.setForeground(fg); outputTextArea.setFont(fn); inputPanel.add(l1[0]); inputPanel.add(c1[0]); inputPanel.add(l2[0]); inputPanel.add(l1[1]); inputPanel.add(c1[1]); inputPanel.add(l2[1]); inputPanel.add(l1[2]); inputPanel.add(c1[2]); inputPanel.add(t1[2]); inputPanel.add(l1[3]); inputPanel.add(t1[0]); inputPanel.add(l2[3]); inputPanel.add(l1[4]); inputPanel.add(t1[1]); inputPanel.add(l2[4]); c1[0].addItemListener(this); c1[1].addItemListener(this); c1[2].addItemListener(this); t1[0].addActionListener(this); t1[1].addActionListener(this); t1[2].addActionListener(this); double TK=T+273.0; gm=new idealgazModeli(g1,TK,P); jt=new JTable(gm); jt.setBackground(bg); jt.setFont(fn); setArea(); outputPanel.add(outputTextArea,BorderLayout.NORTH); outputPanel.add(jt,BorderLayout.SOUTH); totalPanel.add(inputPanel,BorderLayout.NORTH); totalPanel.add(outputPanel,BorderLayout.SOUTH); c.add(totalPanel,BorderLayout.NORTH); } public void setArea() { t1[0].setText(Double.toString(T)); t1[1].setText(Double.toString(P)); String s=""; s+="Dr. Turhan Çoban, \n"; s+="Ege Üniversitesi, Mühendislik Fakultesi, Makina Müh.\n"; s+="tel : 0232 3434000-5387\n"; s+="email : turhan.coban@ege.edu.tr \n"; //note if you would like to list additional information on the screen //add to string s s+="Gaz Formülü : "+g1.toString()+"\n"; gm.setValues(g1,unit,base,T,P); outputTextArea.setText(s); } public void itemStateChanged(ItemEvent ev) { gasName=(String)c1[2].getSelectedItem(); t1[2].setText(gasName); unit=(String)c1[0].getSelectedItem(); if(unit=="EN") {l2[3].setText(" derece F "); l2[4].setText(" psia (lbf/in^2) ");} else {l2[3].setText(" derece F "); l2[4].setText(" bar ");} base=(String)c1[1].getSelectedItem(); g1=new gaz(gasName); g1.base(base); g1.unit(unit); t1[0].setText(" "); t1[1].setText(" "); setArea(); repaint(); } public void actionPerformed( ActionEvent e) { if(e.getSource()==t1[2]) { String st1=(String)c1[2].getSelectedItem(); gasName=st1; String st2=t1[2].getText(); for(int j=0;j