import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class roots3 extends Applet implements ActionListener
{
    private Label prompt1,prompt2;
    private TextField input;
    TextArea t;
    Panel YaziPaneli;
    int n;
    String s;

    public void init()
    {
        setBackground(Color.lightGray);
        YaziPaneli=new Panel();
        YaziPaneli.setFont(new Font("Serif",Font.BOLD,12));
        YaziPaneli.setLayout( new GridLayout(3,1) );
        t=new TextArea(8,47);
        prompt1= new Label("Roots of a cubic polynomial: a[0]+a[1]*x+...+a[3]*x^3=0");
        prompt2= new Label("enter coefficients of degree 3 polynomial : ");
        input = new TextField(30);
        YaziPaneli.add(prompt1);
        YaziPaneli.add(prompt2);
        YaziPaneli.add(input);
        add(YaziPaneli);
        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;
                 String s="";
                 while(token.hasMoreTokens())
                 {
                 Double ax=new Double(token.nextToken());
                 a[j++]=ax.doubleValue();
                 }
                 z=Matrix.poly_rootsC(a);
                 s=Matrix.toStringT(z)+"\n";
                 z=Matrix.cubic_rootsC(a);
                 s+=Matrix.toStringT(z)+"\n";
                 int i=0;
                 t.setText(s);
                 input.setText("");
    }
}
