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

public class kok3 extends JFrame implements ActionListener
{
    private JLabel prompt1,prompt2;
    private JTextField input;
    JTextArea t;
    JPanel YaziPaneli;
    int n;
    String s;
    Container c;
    public kok3()
    {
        super("3üncü dereceden polinomun kökleri");
        c=getContentPane();
        c.setLayout(new FlowLayout());
        YaziPaneli=new JPanel();
        YaziPaneli.setFont(new Font("Serif",Font.BOLD,12));
        YaziPaneli.setLayout( new GridLayout(3,1) );
        t=new JTextArea();
        t.setBackground(c.getBackground());
        prompt1= new JLabel("a[0]+a[1]*x+a[2]*x^2+a[3]*x^3=0");
        prompt2= new JLabel("3üncü dereceden polinomun katsayılarını giriniz : ");
        input = new JTextField(30);
        input.setBackground(c.getBackground());
        YaziPaneli.add(prompt1);
        YaziPaneli.add(prompt2);
        YaziPaneli.add(input);
        c.add(YaziPaneli);
        c.add(t);
        input.addActionListener(this);
    }

    public void  actionPerformed(ActionEvent e)
    {
            s=input.getText();
            StringTokenizer token=new StringTokenizer(s);
            t.setText("");
            n=token.countTokens()-1;
            int m=n+1;
            double a[]=new double[m];
            complex z[]=new complex[n];
            for(int i=0;i<n;i++)
            {
            z[i]=new complex();
            }
            int j=0;
                 while(token.hasMoreTokens())
                 {
                 Double ax=new Double(token.nextToken());
                 a[j++]=ax.doubleValue();
                 }
                 z=Matrix.cubic_rootsC(a);
                 int i=0;
                 t.setText(Matrix.toStringT(z));
                 input.setText("");
    }

      public static void main(String[] args)
      {
      kok3 pencere= new kok3();
      pencere.addWindowListener(new BasicWindowMonitor());
      pencere.setSize(350,300);
      pencere.setVisible(true);
      }
}
