import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class Valgusfoor1 extends Applet implements Runnable{ int seisund=1; public Valgusfoor1(){ new Thread(this).start(); } public void paint(Graphics g){ for(int i=0; i<4; i++){ Valgusfoor2 foor1=new Valgusfoor2(g, 100, 100); Valgusfoor2 foor2=new Valgusfoor2(g, 100, 100); Valgusfoor2 foor3=new Valgusfoor2(g, 100, 100); Valgusfoor2 foor4=new Valgusfoor2(g, 100, 100); } } public void run(){ int seisund=1; while(true){ try{Thread.sleep(2000);}catch(Exception ex){} seisund++; if(seisund>3){seisund=1;} switch(seisund){ case 1: foor1.setGreen(); foor2.setRed(); foor3.setGreen(); foor4.setRed(); break; case 2: foor1.setYellow(); foor2.setYellow(); foor3.setYellow(); foor4.setYellow(); break; case 3: foor1.setGreen(); foor2.setRed(); foor3.setGreen(); foor4.setRed(); break; } } } public static void main(String argumendid[]){ Frame f=new Frame("Foor"); f.setSize(1000, 900); f.add(new Valgusfoor1()); } } class Valgusfoor2{ int seisund=1; public void Valgusfoor2(Graphics g, int x, int y){ g.drawRect(x, y, x+70, y-200); g.drawLine(x, y-200, x+20, y-210); g.drawLine(x+70, y-200, x+105, y-210); g.drawLine(x+20, y-210, x+105, y-210); g.drawLine(x+70, y, x+105, y-20); g.drawLine(x+105, y-20, x+105, y-210); } public void setGreen(){ g.setColor(Color.green); fillOval(); g.setColor(Color.black); fillOval(); fillOval(); } public void setYellow(){ g.setColor(Color.green); fillOval(); g.setColor(Color.black); fillOval(); fillOval(); } public void setRed(){ g.setColor(Color.green); fillOval(); g.setColor(Color.black); fillOval(); fillOval(); } }