import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class jalgratas extends Applet implements ActionListener, Runnable{ TextField kiiri=new TextField(""); Button nupp=new Button(" Joonista "); boolean veel=true; int samm = 0; int sammS = 0; int sammK = 0; int sammV = 0; double nurkS1 = 0; double nurkS2 = 0; double nurkK = 0; double nurkV = 0; int ooteaeg=300; //ms public jalgratas(){ new Thread(this).start(); } public void run(){ while(veel){ paint(this.getGraphics()); try{ Thread.sleep(ooteaeg); } catch(Exception e){e.printStackTrace();} } } public void init(){ // add(kiiri); // add(nupp); nupp.addActionListener(this); kiiri.addActionListener(this); } public void paint(Graphics g){ g.setColor(Color.gray); g.fillRect(0, 0, getSize().width, getSize().height); //int nr=Integer.parseInt(kiiri.getText().trim()); int nr=30; int nrKeskmine = 20; int nrVaikene = 10; // g.setColor(Color.white); // g.fillRect(0, 0, getSize().width, getSize().height); int r = 100; int x = 0; int y = r; double nurgavahe = ( 2*Math.PI ) / nr; double nurk=0; if (samm == 0) { samm++; } else if (samm == 1){ samm++; nurk = 2* (nurgavahe / 3); } else { nurk = nurgavahe / 3; samm = 0; } for (int k=0; k<=nr; k++){ g.setColor(Color.black); g.drawLine(120, 240,120-x, 240+y); g.drawLine(120, 240,121-x, 241+y); g.drawLine(120, 240,119-x, 239+y); x = (int)Math.round(Math.sin(nurk)*r); y = (int)Math.round(Math.cos(nurk)*r); nurk = nurk+nurgavahe; // g.setColor(Color.black); // g.fillOval(35, 155, 170, 170); } g.setColor(Color.black); g.drawOval(29, 149, 182, 182); g.drawOval(30, 150, 180, 180); g.setColor(Color.yellow); g.fillOval(31, 151, 179, 179); // joon ratta sees int joonX = (int)Math.round(Math.sin(nurkS1)*r); int joonY = (int)Math.round(Math.cos(nurkS1)*r); nurkS1 = nurkS1-(nurgavahe / 3); g.setColor(Color.black); g.drawLine(120, 240,120-joonX, 240+joonY); // ULEKANDE SUUR RATAS int rs = 95; int xs = 0; int ys = rs; double nurgavahes = ( 2*Math.PI ) / nr; double nurks=0; if (sammS == 0) { sammS++; } else if (sammS == 1){ sammS++; nurks = 2* (nurgavahes / 3); } else { nurks = nurgavahes / 3; sammS = 0; } for (int kk=0; kk<=nr; kk++){ g.setColor(Color.black); g.drawLine(390, 240, 390-xs, 240+ys); g.drawLine(390, 240, 391-xs, 241+ys); g.drawLine(390, 240, 389-xs, 239+ys); xs = (int)Math.round(Math.sin(nurks)*rs); ys = (int)Math.round(Math.cos(nurks)*rs); nurks = nurks+nurgavahes; // g.setColor(Color.black); // g.fillOval(305, 155, 170, 170); } g.setColor(Color.black); g.drawOval(299, 149, 182, 182); g.drawOval(301, 151, 179, 179); g.setColor(Color.yellow); g.fillOval(301, 151, 179, 179); // joon ratta sees joonX = (int)Math.round(Math.sin(nurkS2)*rs); joonY = (int)Math.round(Math.cos(nurkS2)*rs); nurkS2 = nurkS2-(nurgavahes / 3); g.setColor(Color.black); g.drawLine(390, 240, 390-joonX, 240+joonY); g.drawLine(120, 150, 390, 150); g.drawLine(120, 330, 390, 330); // ULEKANDE KESKMINE RATAS int rk = 65; int xk = 0; int yk = rk; double nurgavahek = ( 2*Math.PI ) / nrKeskmine; double nurkk=0; if (sammK == 0) { sammK++; } else if (sammK == 1){ sammK++; nurkk = 2* (nurgavahek / 3); } else { nurkk = nurgavahek / 3; sammK = 0; } for (int kkk=0; kkk<=nrKeskmine; kkk++){ g.setColor(Color.black); g.drawLine(390, 240, 390-xk, 240+yk); g.drawLine(390, 240, 391-xk, 241+yk); g.drawLine(390, 240, 389-xk, 239+yk); xk = (int)Math.round(Math.sin(nurkk)*rk); yk = (int)Math.round(Math.cos(nurkk)*rk); nurkk = nurkk+nurgavahek; // g.setColor(Color.black); // g.fillOval(335, 185, 140, 140); } g.setColor(Color.black); g.drawOval(329, 179, 122, 122); g.drawOval(331, 181, 119, 119); g.setColor(Color.white); g.fillOval(330, 180, 120, 120); // joon ratta sees joonX = (int)Math.round(Math.sin(nurkK)*rk); joonY = (int)Math.round(Math.cos(nurkK)*rk); nurkK = nurkK-(nurgavahek / 3); g.setColor(Color.black); g.drawLine(390, 240, 390-joonX, 240+joonY); g.drawLine(120, 150, 390, 180); g.drawLine(120, 330, 390, 300); // ULEKANDE VAIKE RATAS int rv = 36; int xv = 0; int yv = rv; double nurgavahev = ( 2*Math.PI ) / nrVaikene; double nurkv=0; if (sammV == 0) { sammV++; } else if (sammV == 1){ sammV++; nurkv = 2* (nurgavahev / 3); } else { nurkv = nurgavahev / 3; sammV = 0; } for (int kv=0; kv<=nrVaikene; kv++){ g.setColor(Color.black); g.drawLine(390, 240, 390-xv, 240+yv); g.drawLine(390, 240, 391-xv, 241+yv); g.drawLine(390, 240, 389-xv, 239+yv); xv = (int)Math.round(Math.sin(nurkv)*rv); yv = (int)Math.round(Math.cos(nurkv)*rv); nurkv = nurkv+nurgavahev; // g.setColor(Color.black); // g.fillOval(365, 215, 50, 50); } g.setColor(Color.black); g.drawOval(359, 209, 62, 62); g.drawOval(361, 211, 59, 59); g.setColor(Color.yellow); g.fillOval(360, 210, 60, 60); // joon ratta sees joonX = (int)Math.round(Math.sin(nurkV)*rv); joonY = (int)Math.round(Math.cos(nurkV)*rv); nurkV = nurkV-(nurgavahev / 3); g.setColor(Color.black); g.drawLine(390, 240, 390-joonX, 240+joonY); g.setColor(Color.black); g.drawLine(120, 150, 390, 210); g.drawLine(120, 330, 390, 270); } public void actionPerformed(ActionEvent e){ } }