You are on page 1of 3

package TAREA; import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.

JFrame; /** * * @author GUNS ROSE */ public class semaforo extends JFrame implements ActionListener { TextArea t2; Button b2; TextArea t1; Conteo c1,c2; public void init() { setSize(250,100); setVisible(true); t1= new TextArea(); t1.setBounds(1,1, 1, 1); add(t1); b2=new Button ("pausar"); b2.setBounds(120, 40, 10,20); add(b2); t2= new TextArea (); t2.setBounds(5,5,100,190); add(t2); setLayout(new GridLayout(1,1)); add(t1); add(t2); add(b2); b2.addActionListener(this); } public void empezar(){ c1 = new Conteo(1000,t1,t2); c1.start(); } public void actionPerformed(ActionEvent e){ //if(e.getSource().equals(b1)){ // //empezar(); //c1.start(); } //if(e.getSource().equals(b2)){ // //c1.stop(); // }

} class Conteo extends Thread{ long tiempo;

TextArea Area; TextArea Area2; boolean contando = true; public Conteo(long tiempo, TextArea Area,TextArea Area2){ this.tiempo=tiempo; this.Area = Area; this.Area2=Area2; } public void run(){ while(contando){ Area.setBackground(Color.GREEN); try{ sleep(tiempo); } catch(InterruptedException e){ } Area2.setBackground(Color.RED); try{ sleep(tiempo); }catch(InterruptedException e){ } Area.setBackground(Color.YELLOW); try{ sleep(tiempo); } catch(InterruptedException e){ } Area2.setBackground(Color.YELLOW); try{ sleep(tiempo); }catch(InterruptedException e){ } Area .setBackground(Color.RED); try{sleep(tiempo); } catch(InterruptedException e){ } Area2.setBackground(Color.GREEN); try{ sleep(tiempo); }catch(InterruptedException e){ } } } public static void main (String []args){ semaforo sema= new semaforo();

sema.init(); sema.empezar();

} }

You might also like