import java.util.*; import java.io.*; import java.applet.Applet; import java.awt.*; import java.awt.event.*; public class pendel extends Applet implements Runnable, ActionListener{ Button valja=new Button(" Lõpp "); public pendel(){ setLayout(new BorderLayout()); add(valja, BorderLayout.SOUTH); valja.addActionListener(this); new Thread(this).start(); } int nr=2; double nurk=0; double raadius=100; double samm=0.05; boolean veel=true; public void run(){ while(veel){ joonista(); } } public void update(Graphics g){paint(g);} public void joonista(){ Graphics g=this.getGraphics(); if(g!=null){ int keskx=getSize().width/2; int kesky=getSize().height/2; g.setColor(Color.blue); g.drawLine(keskx, kesky-100, (keskx+10)+(int)(raadius*Math.sin(nurk))-5, (kesky+10)+(int)(raadius*Math.cos(nurk))-5); g.fillOval(keskx+(int)(raadius*Math.sin(nurk))-5, kesky+(int)(raadius*Math.cos(nurk))-5, 20, 20); try{Thread.sleep(30);}catch(Exception e){} g.setColor(Color.white); g.drawLine(keskx, kesky-100, (keskx+10)+(int)(raadius*Math.sin(nurk))-5, (kesky+10)+(int)(raadius*Math.cos(nurk))-5); g.fillOval(keskx+(int)(raadius*Math.sin(nurk))-5, kesky+(int)(raadius*Math.cos(nurk))-5, 20, 20); if((nurk>Math.PI/nr) && (samm>0)){samm=-samm;nr=nr+1;} if((nurk<-Math.PI/nr) && (samm<0)){samm=-samm;nr=nr+1;} nurk=nurk+samm; } } public void actionPerformed(ActionEvent e){ if(e.getSource()==valja){ System.exit(0); } } public static void main(String agumendid[]){ Frame f=new Frame(); f.add(new pendel()); f.setBackground(Color.white); f.setSize(300, 300); f.setVisible(true); f.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } } ); } }