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

public class ColorFlash extends Frame 
implements Runnable, ActionListener
{
 Lumatron l;
 Color renk;
 int treadtime;
 private Thread t1;
 private boolean s1,flag;
 private Button button1;
 int radius;
 private MenuBar bar;
 private Menu LumatronRengi,baslat;
 private MenuItem renkler[],baslatdurdur[];
 private CheckboxMenuItem readOnly; 
 
 public ColorFlash()
 {
 super("Lumatron renk flash");
 setSize(500,500);
 s1=true;
 l=new Lumatron();
 renk=l.getColor();
 treadtime=l.flash;
 radius=10;
 bar=new MenuBar();
 LumatronRengi=new Menu("Lumatron Rengi");
 baslat=new Menu("baslat/durdur");
 renkler=new MenuItem[17];
 baslatdurdur=new MenuItem[2];
 for(int i=0;i<17;i++)
 {
   renkler[i]=new MenuItem(l.s[i]);
   LumatronRengi.add(renkler[i]);
   renkler[i].addActionListener(this);
 }
 baslatdurdur[0]=new MenuItem("Baslat");
 baslatdurdur[1]=new MenuItem("Durdur");
 baslat.add(baslatdurdur[0]);
 baslat.add(baslatdurdur[1]);
 baslatdurdur[0].addActionListener(this);
 baslatdurdur[1].addActionListener(this); 
 bar.add(LumatronRengi);
 bar.add(baslat);
 //button1.addActionListener(this);
 //add(button1);
 //showStatus("Renk : "+l.renk+" hiz : "+(1000/l.flash)+" Hz" );
 setMenuBar(bar);
 setVisible(true); 
}
 
 public void start()
 {
 t1=new Thread(this,"T1");
 t1.start();
 }
 
 public void stop()
 {
 t1.stop();
 }
 
 public void actionPerformed(ActionEvent e)
 {
 if(e.getSource()==baslatdurdur[0])
   if(s1)
   {
   //showStatus("Renk : "+l.renk+" hiz : "+(1000/l.flash)+" Hz" );
   t1.resume();
   s1=false;
   }
   else
   {
   //showStatus("durduruldu");
   t1.suspend();
   s1=true;
   }
   for(int i=0;i<17;i++)
   {
     if(e.getSource()==renkler[i])
     {
     l.setLumatron(i);
     renk=l.getColor();
     s1=false;
     }
   }
 }

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


 public void paint(Graphics g)
 { 
 g.setColor(Color.white); 
 g.fillOval(160-radius/2,160-radius/2,radius,radius);
 g.setColor(renk); 
 g.fillOval(160-radius/2,160-radius/2,radius,radius);}
}
