import java.applet.Applet; import java.awt.*; import java.awt.Graphics; import java.awt.event.*; public class sin4 extends Applet implements Runnable, ActionListener { private int a = 0; private Image image1 = null; private Graphics graph1 = null; private Thread move = null; int i1 = 50; int i3 = 10; TextField tf1=new TextField("Raadius"); // raadius TextField tf3=new TextField("Kiirus"); // kiirus public void init() { add(tf1); add(tf3); tf1.addActionListener(this); tf3.addActionListener(this); start(); } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { int xo = 0; int yo; int xn = 0; int yn; if (image1 == null) { image1 = createImage(getSize().width, getSize().height); graph1 = image1.getGraphics(); } yo = (int)(50 * Math.sin((double)(xn+a)*Math.PI/i3) + getSize().height / 2); graph1.setColor(Color.white); graph1.fillRect(0,0,getSize().width, getSize().height); graph1.setColor(Color.green); while(xn < getSize().width) { yn = (int)(50 * Math.sin((double)(xn+a)*Math.PI/i3) + getSize().height / 2); graph1.drawLine(xo, yo, xn, yn); yo=yn; xo=xn; xn++; } g.drawImage(image1, 0,0,this); } public void run() { while (Thread.currentThread() == move) { a = a + i3; if (a >= 360) a = 0; repaint(); try { Thread.sleep(20); } catch (InterruptedException e) {} } } public void actionPerformed(ActionEvent e){ i1=Integer.parseInt(tf1.getText().trim()); i3=Integer.parseInt(tf3.getText().trim()); start(); move = new Thread(this); move.start(); } public void stop() { move = null; } }