import java.awt.*;

import java.applet.Applet;

import java.awt.event.*;



public class PolinomunKokleri extends Applet implements ActionListener

{

// polinom a*x^2+b*x+c=0

private Panel YaziPaneli;

Label prompt1; 

Label prompt2;

Label prompta; 

TextField inputa; //

Label promptb; //

TextField inputb; //

Label promptc; //

TextField inputc; //

double a,b,c; //polinomun katsayilari

double delta=0.0; //determinant 

double x1,x2; //kokler

public void init()

{

setBackground(Color.lightGray); 

YaziPaneli=new Panel();

YaziPaneli.setFont(new Font("Serif",Font.BOLD,12));

YaziPaneli.setLayout( new GridLayout(4,2) );

prompt1=new Label("a*x^2+b*x+c = 0");

prompt2=new Label("Polinomunun kokleri");

prompta=new Label(" a : ");

inputa =new TextField(5);

inputa.addActionListener(this);

promptb=new Label(" b : ");

inputb =new TextField(5);

inputb.addActionListener(this);

promptc=new Label(" c : ");

inputc =new TextField(5);

inputc.addActionListener(this);

YaziPaneli.add(prompt1); 

YaziPaneli.add(prompt2);

YaziPaneli.add(prompta);

YaziPaneli.add(inputa);

YaziPaneli.add(promptb);

YaziPaneli.add(inputb); 

YaziPaneli.add(promptc);

YaziPaneli.add(inputc);

add(YaziPaneli);

}

public void paint(Graphics g)

{

g.setColor(Color.blue);

g.setFont(new Font("Serif",Font.BOLD,14));

g.drawString("Polinomun Kokleri: ",70,175);

g.setColor(Color.black);

g.setFont(new Font("Serif",Font.BOLD,12));

if(delta<0)

{

g.drawString("Kok 1 :"+(-b/2.0/a)+"+ i* "+Math.sqrt(- delta)/2.0/a,100,190 );

g.drawString("Kok 2 :"+(-b/2.0/a)+"- i* "+Math.sqrt(-delta)/2.0/a,100,205); 

}

if(delta==0)

{

g.drawString("Kok 1 :"+(-b/2.0/a),100,190 );

g.drawString("Kok 2 :"+(-b/2.0/a),100,205 );

}

if(delta>0)

{

x1=-b/2.0/a+Math.sqrt(delta)/20/a;

x2=-b/2.0/a-Math.sqrt(delta)/2.0/a;

g.drawString("Kok 1 :"+x1,100,190 );

g.drawString("Kok 2 :"+x2,100,205); 

}

}

public void actionPerformed( ActionEvent e)

{

Double sayi1=new Double(inputa.getText() );

Double sayi2=new Double(inputb.getText() );

Double sayi3=new Double(inputc.getText() );

a=sayi1.doubleValue();

b=sayi2.doubleValue();

c=sayi3.doubleValue();

delta=b*b-4.0*a*c;

repaint();

}

}