
import java.awt.event.*; 

import javax.swing.*; 

import javax.swing.border.*;


import java.awt.*; 
import java.util.*; 
import java.applet.Applet; 
import java.net.*;
import java.io.*;

public class parsetest extends JFrame implements WindowListener {

    TextArea  results = new TextArea("",12, 58);
    JButton  doIni = new JButton("Process INI"); 
    JLabel  Label1 = new JLabel("Enter file names for example", Label.LEFT); 

    TextField  iniName = new TextField("c:\\vbtojava\\initest.ini",30);
    JButton  doComma = new JButton("Process Comma Delimted"); 
    TextField  commaName = new TextField("c:\\vbtojava\\comma.txt",30);
    File source_file = null;
    FileReader source = null;
    BufferedReader dataIn = null;
    String textline = null;
    String parseleft = null;
    String parseright = null;
    String resultOutput = null;
    int offset = 0;
    int total = 0;


    public parsetest() {
      addWindowListener(this);
      getContentPane().setLayout(null);
      setBounds (91, 78, 454, 319 );
      getContentPane().setFont(new Font ("Dialog", Font.PLAIN, 11));
      getContentPane().setBackground(Color.lightGray);

      getContentPane().add(results);
      results.setBounds( getInsets().left + getInsets().right + 48,  getInsets().top + getInsets().bottom + 176, 353, 97);

      doIni.setFont(new Font ("Dialog", Font.PLAIN, 12));
      getContentPane().add(doIni);
      doIni.setBounds( getInsets().left + getInsets().right + 256,  getInsets().top + getInsets().bottom + 80, 145, 33);

      doIni.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent ev) { // clicked
          try{
            source = new FileReader(iniName.getText());
            dataIn = new BufferedReader(source);
            for (;;){
                  textline = dataIn.readLine();
                  if (textline == null){ break;}
                  offset = textline.indexOf("=");
                  if ( offset > 0){
                    parseleft = textline.substring(0, offset);
                    parseleft = parseleft.trim();      
                    parseright = textline.substring(offset+1);
                    parseright =parseright.trim();
                    if (resultOutput == null){
                      resultOutput = parseleft + " is " + parseright + "\n";
                    } else {
                      resultOutput = resultOutput + parseleft + " is " + parseright + "\n";
                    } // end else 
                  } // end if offset > 0
            } // end forever
            results.setText(resultOutput);
          }catch(IOException e) {System.err.println(e);}
        } // end clicked
      }); // end doIni clicked

      getContentPane().add(Label1);
      Label1.setBounds( getInsets().left + getInsets().right + 48,  getInsets().top + getInsets().bottom + 16, 337, 33);

      getContentPane().add(iniName);
      iniName.setBounds( getInsets().left + getInsets().right + 48,  getInsets().top + getInsets().bottom + 80, 185, 33);

      doComma.setFont(new Font ("Dialog", Font.PLAIN, 12));
      getContentPane().add(doComma);
      doComma.setBounds( getInsets().left + getInsets().right + 256,  getInsets().top + getInsets().bottom + 128, 145, 33);

      doComma.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent ev) { // clicked
          try{
            source = new FileReader(commaName.getText());
            dataIn = new BufferedReader(source);
            textline = dataIn.readLine();
            results.setText(textline);
            offset = textline.indexOf(",");
            while ( offset > 0){
              parseleft = textline.substring(0, offset);
              parseleft = parseleft.trim();
              total = total + new Integer(parseleft).intValue();
              textline = textline.substring(offset+1);
              results.setText(results.getText() + "\n" + textline);
              offset = textline.indexOf(",");
            }
            textline = textline.trim();
            total = total + new Integer(textline).intValue();
            results.setText(results.getText() + "\n" + "total is " + total);

          }catch(IOException e) {System.err.println(e);}

        } // end clicked
      }); // end doComma clicked

      getContentPane().add(commaName);
      commaName.setBounds( getInsets().left + getInsets().right + 48,  getInsets().top + getInsets().bottom + 128, 185, 33);
    }  // end init

  public parsetest(String title) {
      this();
      setTitle(title); 
  }

    public void windowClosed(WindowEvent event) {
    }
    public void windowDeiconified(WindowEvent event) {
    }
    public void windowIconified(WindowEvent event) {
    }
    public void windowActivated(WindowEvent event) {
    }
    public void windowDeactivated(WindowEvent event) {
    }
    public void windowOpened(WindowEvent event) {
    }
    public void windowClosing(WindowEvent event) {
            System.exit(0);
         }

    public static void main(String args[]){
      parsetest f = new parsetest();
      f.show();
      }


}  // end class

