import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.io.*;
import java.util.*;


public class inputfixi extends Thread implements ActionListener
{
	 Container c; 
	 functiongenerator_fixi fg;
	 JLabel jl;
	 JComboBox<String> ne;
	 JTextField jt[];
	 JButton bb;
	 boolean basildi;
	 int n;
	 String s[];
	 String s1;
	 JPanel inputPanel;
	 JPanel inputPanel1;

	 public inputfixi(String isim,String fonksiyon[])
	 {
     String ss[]={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29",};
	 inputPanel=new JPanel();
     inputPanel.setLayout(new GridLayout(2,1));	 
	 n=1;
	 s=new String[n];
	 jl=new JLabel("Number of equations:");
	 ne=new JComboBox<String>(ss);
	 jl.setFont(new Font("SansSerif",Font.PLAIN,20));
	 ne.setFont(new Font("SansSerif",Font.PLAIN,20));
	 ne.addActionListener(this);
	 inputPanel.add(jl);
	 inputPanel.add(ne);
	 fg=new functiongenerator_fixi();
	 bb=new JButton("push the button when you finish writing the function : variables : x[0],x[1]...");
	 JScrollPane jsp=new JScrollPane(inputPanel);
     JFrame cerceve=new JFrame("N Dimensional function input window : a sample function : \"x[0]*x[0]-x[1]\",\"x[1]-2*x[0]+3\" ");
     cerceve.addWindowListener(new BasicWindowMonitor());
     c=cerceve.getContentPane();
     c.setLayout(new BorderLayout());
     c.add(jsp,BorderLayout.NORTH);
     c.add(bb,BorderLayout.SOUTH); 
     bb.addActionListener(this);         
     cerceve.pack();
     cerceve.setSize(500,600);
     cerceve.setVisible(true);
     basildi=false;

     }     
     
     public String[] vericiktisi()
     {  
        while(!basildi)
        {
        try {Thread.sleep(100);} 
        catch(InterruptedException e)  {System.err.println(e.toString());}
        } 
	    return s;
	 }
	 	  
     protected void finalize() throws Throwable
     {super.finalize();}
     
public void actionPerformed( ActionEvent e)
{
  if(e.getSource()==ne)
  {n=Integer.parseInt((String)ne.getSelectedItem());
   s=new String[n];
   jt=new JTextField[n];
   inputPanel1=new JPanel();
   inputPanel1.setLayout(new GridLayout(n,1));	 
   for(int i=0;i<n;i++)	 		 
	 {jt[i]=new JTextField("");
	  jt[i].setFont(new Font("SansSerif",Font.PLAIN,20));
	  jt[i].addActionListener(this);
	  inputPanel1.add(jt[i]);
	 }
   
  }
  if(e.getSource()==bb)
  {     for(int i=0;i<n;i++)
        {s[i]=jt[i].getText();}
        fg.addfunction(s);s1=fg.createfunction();
        basildi=true;
        try{fg.finalize();finalize();} catch(Throwable e1) {System.err.println("input error");} 
  } 
  JScrollPane jsp1=new JScrollPane(inputPanel1);
  c.add(jsp1,BorderLayout.CENTER);    
  c.validate();
  c.repaint();
}
}