import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import trafikIsigiSWP;

class isikKontroluThread extends Thread
{
JFrame a;
public double zaman=12.0;

   public isikKontroluThread(JFrame ai)
   {
   a=ai;
   }

   public void run()
   {
   while(true)
   {
    a.repaint();
    //12 saniye bekle
    try {Thread.sleep((int)(zaman*1000));}
    catch(InterruptedException e)
    {System.err.println(e.toString());}
   }
   }

   public void setZaman(double zi)
   {
     zaman=zi;
   }

   public double getZaman()
   {
     return zaman;
   }

}

public class trafikIsigiSWF extends JFrame implements ActionListener
{
    isikKontroluThread yik;
    private char which_light='y';
    private JButton light_switch;
    JTextField t1;
    JLabel l1,l2;
    trafikIsigiSWP ti;
    Container co;
    JPanel jp;

    public trafikIsigiSWF() {
        super("trafik ışığı");
        co=getContentPane();
        co.setLayout(new BorderLayout());
        JPanel jp=new JPanel();
        jp.setLayout(new GridLayout(1,4));
        light_switch = new JButton("Switch");
        light_switch.setForeground(Color.black);
        light_switch.setBackground(Color.lightGray);
        t1=new JTextField("12");
        l1=new JLabel("ışık yanma zamanı : ");
        l2=new JLabel("saniye");
        ti=new trafikIsigiSWP();
        jp.add(light_switch);
        jp.add(l1);
        jp.add(t1);
        jp.add(l2);
        co.add(jp,BorderLayout.NORTH);
        co.add(ti,BorderLayout.CENTER);
        light_switch.addActionListener(this);
        t1.addActionListener(this);
        yik=new isikKontroluThread(this);
        yik.start();
    }
public void actionPerformed(ActionEvent e)
{
  if(e.getSource()==light_switch)
  {
     repaint();
     //try {Thread.sleep(1000);} catch (Exception exc) {}
  }
  else if(e.getSource()==t1)
  {
     Double i1=new Double(t1.getText());
     yik.setZaman(i1.doubleValue());
  }
}

 public static void main(String[] args)
      {
      trafikIsigiSWF pencere= new trafikIsigiSWF();
      pencere.addWindowListener(new BasicWindowMonitor());
      pencere.setSize(400,100);
      pencere.setVisible(true);
      }
}
