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

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

   public isikKontroluThread(Applet 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 Button light_switch;
    private static int x=10;
    private static int y= 40;
    private static int h=360;
    private static int w=100;
    private static int radius=40;
    private static int hight_diff=30;
    TextField t1;
    Label l1,l2;
    public trafikIsigiSWF() {
        light_switch = new Button("Switch");
        light_switch.setForeground(Color.black);
        light_switch.setBackground(Color.lightGray);
        t1=new TextField("12");
        l1=new Label("ışıkk yanma zamanı : ");
        l2=new Label("saniye");
        add(light_switch);
        add(l1);
        add(t1);
        add(l2);
        light_switch.addActionListener(this);
        t1.addActionListener(this);
        yik=new isikKontroluThread(this);
        yik.start();
    }

    public void paint(Graphics g) {
        g.setColor(Color.black);
        g.fillRect(x,y,w,h);
        g.setColor(Color.white);
        g.drawRect(x-1,y-1,w+2,h+2);
        g.drawRect(x-2,y-2,w+4,h+4);
        switch(which_light) {
            case 'r':
                which_light='g';
                g.setColor(Color.lightGray);
                g.fillOval(x+10,y+hight_diff,radius*2,radius*2);
                g.fillOval(x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
                g.setColor(Color.green);
                g.fillOval(x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
                break;
            case 'y':
                which_light='r';
                g.setColor(Color.lightGray);
                g.fillOval(x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
                g.fillOval(x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
                g.setColor(Color.red);
                g.fillOval(x+10,y+hight_diff,radius*2,radius*2);
                break;
            case 'g':
                which_light='y';
                g.setColor(Color.lightGray);
                g.fillOval(x+10,y+hight_diff,radius*2,radius*2);
                g.fillOval(x+10,y+hight_diff*3+radius*4,radius*2,radius*2);
                g.setColor(Color.yellow);
                g.fillOval(x+10,y+hight_diff*2+radius*2,radius*2,radius*2);
                repaint(1000);
        }
    }

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);
      }
}
