import java.applet.*; import java.awt.*; public class Graphica extends Applet implements Runnable{ Graphics g; Color bgColor; int TOPX=100; int TOPY=10; int X = 0; int Y = 0; int quant=50; float L=150; double Xm=100; float Tm=100; long T=0; double kzat=0.999; public void init() { g = getGraphics(); bgColor = new Color (255,255,255); setBackground(bgColor); get_coordinates(); } { (new Thread(this)).start(); } public void run() { while (true) { get_coordinates(); repaint(); T=T+quant; Xm=Xm*kzat; try { Thread.sleep(quant); } catch (InterruptedException e) { } } } void get_coordinates() { double S; S=Xm*Math.cos(Math.sqrt(9.8/L)*(T/Tm)); //Liigub vastavalt määrustele //X=Xm*cos(wt); //t=T/1000 (aeg) // w=sqrt(g/l) double a; a=(Math.asin((S/2)/L))*2; X=(new Double(L*Math.sin(a)).intValue())+TOPX; Y=(new Double(L*Math.cos(a)).intValue())+TOPY; } public void paint(Graphics g) { g.setColor(Color.black); g.drawLine(TOPX-40,TOPY,TOPX+40,TOPY); g.setColor(Color.green); g.drawLine(TOPX,TOPY,X,Y); g.setColor(Color.red); g.fillOval(X-10,Y-10,20,20); } private void initComponents () { setLayout (new java.awt.BorderLayout ()); } }