import java.awt.*; import java.applet.*; import java.awt.event.*; import java.math.*; import java.util.*; public class Eksam1 extends Applet implements AdjustmentListener{ double R; double X=150; double Y=150; double lastX; double lastY; double realX=0; double realY=0; double Nurk=0; double VaheMuut=0.01; Scrollbar vahe=new Scrollbar(Scrollbar.HORIZONTAL,1,10,1,100); Scrollbar kiir=new Scrollbar(Scrollbar.HORIZONTAL,1,10,1,100); Keerutus Tee = new Keerutus(1); public Eksam1(){ setLayout(null); vahe.setSize(280,18); kiir.setBounds(0,20,280,18); add(vahe); add(kiir); vahe.addAdjustmentListener(this); kiir.addAdjustmentListener(this); Tee.start(); } public void paint(Graphics g){ lastX=150; lastY=150; realX=0; realY=0; R=0; for(double i=0;i<1000;i++){ R = R + VaheMuut; realX = X + Math.cos(Nurk)*R; realY = Y + Math.sin(Nurk)*R; g.drawLine((int)realX,(int)realY,(int)lastX,(int)lastY); lastX=realX; lastY=realY; Nurk+=0.1; } } public void adjustmentValueChanged(AdjustmentEvent e){ if(e.getSource()==vahe){ VaheMuut=vahe.getValue()*0.01; } if(e.getSource()==kiir){ System.out.println(kiir.getValue()); Tee.kiirus=(double)(kiir.getValue()*0.1); } } public static void main(String[] args){ Frame f=new Frame(); f.add(new Eksam1()); f.setSize(300,300); f.setVisible(true); f.addWindowListener(new Raamikuular()); } class Keerutus extends Thread{ double kiirus; public Keerutus(double kiirus){ this.kiirus=kiirus; } public void run(){ while(true){ Nurk+=kiirus; repaint(); try{Thread.sleep(150);}catch(Exception e){} } } }; }