import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
//import Lumatron;

public class HuseyinNazli2 extends Applet 
implements Runnable, ActionListener, ItemListener
{
 Lumatron l;
 Color renk;
 int treadtime;
 private Thread t1;
 private boolean s1,flag;
 int radius;
 private List renkler;
 private List sekiller;
 private Panel P;
 private TextArea te1;
 int graphCode;
 int startAngle=0;
 int arcAngle=90;
 private String toSekil[]={"grafik 1 : tam  daire",
                           "grafik 2 : iki  daire dilimi",
                           "grafik 3 : dort daire dilimi",
                           "grafik 4 : sekiz daire dilimi"};

 public void init()
 {
 graphCode=1;
 P=new Panel();
 te1=new TextArea("Copyright :  Huseyin Nazli\n"+
                  "Yazan      :  Turhan Coban \n"+
                  " bu program ucuncu sahislar "+
                  "tarafindan kullanilabilir fakat"+
                  " her turlu kullanim hakki"+
                  " yukaridaki sahislara aitttir ",20,7,TextArea.SCROLLBARS_NONE);

 P.setLayout(new GridLayout(5,1));
 P.setBackground(Color.white);
 s1=true;
 l=new Lumatron();
 renk=l.getColor();
 treadtime=l.flash;
 radius=10;
 renkler=new List(4,false);
 renkler.addActionListener(this);
 renkler.addItemListener(this);
 sekiller=new List(5,false);
 sekiller.addActionListener(this);
 sekiller.addItemListener(this);
 for(int i=0;i<17;i++)
 {
   renkler.add(l.toString(i));
 }
 for(int i=0;i<4;i++)
 {
   sekiller.add(toSekil[i]);
 }
 P.add(renkler);
 P.add(sekiller);
 P.add(te1);
 setLayout(new BorderLayout());
 add(P,BorderLayout.EAST);
 showStatus(l.toString1());
}
 
 public void start()
 {
 t1=new Thread(this,"T1");
 t1.start();
 }
 
 public void stop()
 {
 t1.stop();
 }
 
 public void actionPerformed(ActionEvent e)
 {
   for(int i=0;i<17;i++)
   {
     if(renkler.getSelectedIndex()==i)
     {
     t1.suspend();
     s1=true;
     l.setLumatron(i);
     renk=l.getColor();
     t1.resume();
     s1=false;
     showStatus(l.toString1(i));
     }
   }
   for(int i=0;i<4;i++)
   {
     if(sekiller.getSelectedIndex()==i)
     {
     t1.suspend();
     s1=true;
     graphCode=i+1;
     t1.resume();
     s1=false;
     }
   }
/*
 if(e.getSource()==button1)
   if(s1)
   {
   showStatus("baslatildi");
   t1.resume();
   s1=false;
   }
   else
   {
   showStatus("durduruldu");
   t1.suspend();
   s1=true;
   }
*/
 }

 public void run()
 {
 while(true)
 {
 try{ Thread.sleep(l.flash);}
 catch(InterruptedException e){e.printStackTrace();}
 if(flag)
    radius+=10;
 else
    radius-=10; 
 startAngle+=5%360;
 repaint();
 if(radius>300 ) flag=false;
 else if(radius<0) flag=true;
 } 
 }//end of run

 public void itemStateChanged(ItemEvent e)
 {
 showStatus(l.toString1());
 }//end of itemStateChange

 public void paint(Graphics g)
 { 
  setBackground(Color.gray);
  if(graphCode==1)
  {
   g.setColor(Color.gray);
   g.fillOval(160-radius/2,160-radius/2,radius,radius);
   g.setColor(renk); 
   g.fillOval(160-radius/2,160-radius/2,radius,radius);
  }
  else if(graphCode==2)
  {
   arcAngle=160;
   g.setColor(Color.gray);
   g.fillOval(160-radius/2,160-radius/2,radius,radius);
   g.setColor(renk); 
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+180,arcAngle);
  }
  else if(graphCode==3)
  {
   arcAngle=80;
   g.setColor(Color.gray);
   g.fillOval(160-radius/2,160-radius/2,radius,radius);
   g.setColor(renk); 
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+90,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+180,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+270,arcAngle);
  }
  else if(graphCode==4)
  {
   arcAngle=40;
   g.setColor(Color.gray);
   g.fillOval(160-radius/2,160-radius/2,radius,radius);
   g.setColor(renk); 
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+45,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+90,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+135,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+180,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+225,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+270,arcAngle);
   g.fillArc(160-radius/2,160-radius/2,radius,radius,startAngle+315,arcAngle);

  }


 }//end of paint
}
