import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public class HuseyinNazliSWA extends JApplet 
implements Runnable, ActionListener, ItemListener
{
 Lumatron l;
 Color renk;
 int treadtime;
 private Thread t1;
 private boolean s1,flag;
 int radius;
 private JComboBox renkler;
 private JComboBox sekiller;
 private JPanel P;
 private JTextField 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"};
 Container co;
 private boolean inAnApplet=true;
 
 public HuseyinNazliSWA()
 {
 	  this(true);
 }
 
 public HuseyinNazliSWA(boolean inAnApplet)
 {
 this.inAnApplet=inAnApplet;
 if(inAnApplet)
 { getRootPane().putClientProperty("defeatSystemEventQueueCheck",Boolean.TRUE); }
 }
 
 public void init()
 {	  
 co=getContentPane();
 graphCode=1;
 P=new JPanel();
 te1=new JTextField("Copyright :  Huseyin Nazli\n"+
                  "Yazan      :  Turhan Coban \n"+
                  " bu program ucuncu sahislar "+
                  "tarafindan kullanilabilir fakat"+
                  " her turlu kullanim hakki"+
                  " yukaridaki sahislara aitttir ");
 te1.setEditable(false);
 //te1.setFont(new Font((String)sekiller.getSelectedValue(),Font.BOLD,12));
 te1.setBackground(Color.black);
 P.setLayout(new GridLayout(5,1));
 P.setBackground(Color.black);
 P.setForeground(Color.yellow);
 s1=true;
 l=new Lumatron();
 renk=l.getColor();
 treadtime=l.flash;
 radius=10;
 String renklistesi[]=new String[17];
 for(int i=0;i<17;i++)
 {
   renklistesi[i]=l.toString(i);
 }
 renkler=new JComboBox(renklistesi);
 renkler.setSelectedIndex(0);
 renkler.setBackground(Color.black); 
 renkler.addActionListener(this);
 renkler.addItemListener(this);
 sekiller=new JComboBox(toSekil);
 sekiller.setSelectedIndex(2);  
 sekiller.setBackground(Color.black); 
 sekiller.addActionListener(this);
 sekiller.addItemListener(this);
 P.add(renkler);
 P.add(sekiller);
 P.add(te1);
 co.setLayout(new BorderLayout());
 //co.add(this,BorderLayout.WEST);
 co.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)
 {
 P.setBackground(Color.black); 
 P.setForeground(Color.yellow); 
 }//end of itemStateChange
 
 public void paint(Graphics g1)
 { 
  Graphics2D g=(Graphics2D)g1;
  g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  RenderingHints.VALUE_ANTIALIAS_ON);
  if(graphCode==1)
  {
   g.setColor(Color.black);
   Ellipse2D elips1=new Ellipse2D.Double(160-radius/2,160-radius/2,radius,radius);
   g.fill(elips1);
   //g.fillOval(160-radius/2,160-radius/2,radius,radius);
   g.setColor(renk); 
   g.fill(elips1);
   //g.fillOval(160-radius/2,160-radius/2,radius,radius);
   
  }
  else if(graphCode==2)
  {
   arcAngle=160;
   g.setColor(Color.black);
   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.black);
   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.black);
   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);
  }
 g.setBackground(Color.black);
 }//end of paint
      public static void main(String[] args)
      {
      JFrame frame=new JFrame("Lumatron");
      frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);}});
      }
}
