import java.applet.Applet; import java.awt.*; public class Mote extends Applet implements Runnable{ sona sonad[]=new sona[30]; int juhud[]=new int[12]; Image pilt, sahver; Graphics piltg, sahverg; Thread tr; int pikkus, korgus, tkoht=0, lihtnr=0; String liht[]=new String[5]; Button nupp=new Button("OK"); Label l1=new Label(), l2=new Label("Selgema mudeli koostamiseks tuleb teha moned lihtsustused"); Panel p1=new Panel(), p2=new Panel(); public void init(){ liht[0]="Silla ehitus on ideaalne"; liht[1]="Autod soidavad uhes suunas ning reas"; liht[3]="Autod on hesugused"; liht[4]="Inimesed ei eksi"; l1.setText(liht[0]); p1.setLayout(new BorderLayout()); p1.add("Center", l1); p1.add("East", nupp); p2.setLayout(new GridLayout(1, 2)); p2.add(l2); p2.add(p1); nupp.hide(); l1.hide(); l2.hide(); this.setLayout(new BorderLayout()); add("South", p2); Dimension d=this.size(); pilt=createImage(d.width, d.height); piltg=pilt.getGraphics(); sahver=createImage(d.width, d.height); sahverg=sahver.getGraphics(); sahverg.setColor(Color.white); sahverg.fillRect(0, 0, 400, 400); sonad[ 0]=new sona(piltg, "Sild", 100, 100); sonad[5]=new sona(piltg, "Masin", 300, 100); sonad[10]=new sona(piltg, "Inimene", 200, 300); for(int i=0; i<15; i+=5){sonad[i ].varv(Color.red); sonad[i].joonista();} sonad[1]=new sona(piltg, "Teekate", 80, 80); sonad[2]=new sona(piltg, "Silla pikkus", 180, 80); sonad[3]=new sona(piltg, "Laius", 80, 120); sonad[4]=new sona(piltg, "Looklevus", 180, 120); sonad[6]=new sona(piltg, "Kiirus", 280, 80); sonad[7]=new sona(piltg, "Pikkus", 380, 80); sonad[8]=new sona(piltg, "Mark", 280, 120); sonad[9]=new sona(piltg, "Pikivahe", 380, 120); sonad[11]=new sona(piltg, "Vanus", 80, 280); sonad[12]=new sona(piltg, "Sugu", 180, 280); sonad[13]=new sona(piltg, "Mass", 80, 320); sonad[14]=new sona(piltg, "Laste arv", 180, 320); vahetused(); repaint(); } void ilmne(){ System.out.println("ilmneb tkoht="+tkoht); sonad[juhud[tkoht]].varv(Color.black); sonad[juhud[tkoht++]].joonista(); repaint(); } void vahetused(){ int koht=0, a, b, abi; for(int i=1; i<4; i++)for(int j=0; j<4; j++) juhud[koht++]=i+(i-1)*4+j; for(int i=0; i<100; i++){ a=(int)(Math.random()*12); b=(int)(Math.random()*12); abi=juhud[a]; juhud[a]=juhud[b]; juhud[b]=abi; } } public void start(){tr=new Thread(this); tr.start();} public void run(){ int isekoht=0; while(tr!=null){ if (isekoht<10){ilmne(); try{tr.sleep(500);} catch(Exception e){}} else if (isekoht==12)for(int i=0; i<15; i++)sonad[i].juhusiht(); else if (isekoht<1900){ piltg.setColor(Color.white); for(int j=0; j<40; j++)piltg.fillRect(j*10, 0, 10, 400); piltg.setColor(Color.black); for(int i=0; i<15; i++){sonad[i].servliigu(); } try{tr.sleep(20); } catch(Exception e){} repaint(); //if(isekoht==1000) isekoht=1900; } else if (isekoht==1900)for(int i=0; i<15; i++)sonad[i].suund(10, 15*i, 150); else if (isekoht<=2050){ piltg.setColor(Color.white); for(int j=0; j<40; j++)piltg.fillRect(j*10, 0, 10, 400); piltg.setColor(Color.black); for(int i=0; i<15; i++)sonad[i].edasi(); try{tr.sleep(20); } catch(Exception e){} } /* else if (isekoht==250){for(int i=0; i<15; i++)sonad[i].jkoht(10, 15*i); nupp.show(); l1.show(); l2.show(); } */ if(isekoht<3000)isekoht++; repaint(); }} public void stop(){tr=null;} public void paint(Graphics g){ g.drawImage(pilt, 0, 0, this); } public void update(Graphics g){paint(g);} public boolean action(Event e, Object arg){ if (e.target.equals(nupp)){ if(lihtnr++==0){sonad[1].muudavarv(Color.gray); sonad[4].muudavarv(Color.gray); } if(lihtnr++==1){sonad[3].muudavarv(Color.gray);} if(lihtnr++==2){sonad[8].muudavarv(Color.gray);} if(lihtnr++==3){for(int i=11; i<15; i++)sonad[i].muudavarv(Color.gray);} if(lihtnr==4){nupp.hide(); l1.hide(); l2.hide();} } return true; } }