import java.awt.*; // Miks päike pole keskpunktis??? import java.applet.Applet; import java.awt.image.*;// pildi jaoks import java.awt.event.*; import java.net.*; import java.io.*; import java.util.*; public class p2ikesesysteem extends Applet implements ActionListener, Runnable { TextField tf=new TextField("0.01"); BufferedImage malupilt; Image pilt4=Toolkit.getDefaultToolkit().getImage("4maa.jpg"); double nurk4=0; double raadius4=125; double samm4=0.02; int ooteaeg4=10; //ms boolean veel=true; Image pilt1=Toolkit.getDefaultToolkit().getImage("1päike.jpg"); Image pilt2=Toolkit.getDefaultToolkit().getImage("2merkuur.jpg"); double nurk2=0; double raadius2=60; double samm2=0.02; int ooteaeg2=10; //ms Image pilt3=Toolkit.getDefaultToolkit().getImage("3veenus.jpg"); double nurk3=0; double raadius3=90; double samm3=0.025; int ooteaeg3=10; //ms Image pilt5=Toolkit.getDefaultToolkit().getImage("5mars.jpg"); double nurk5=0; double raadius5=160; double samm5=0.023; int ooteaeg5=10; //ms Image pilt6=Toolkit.getDefaultToolkit().getImage("6jupiter.jpg"); double nurk6=0; double raadius6=200; double samm6=0.015; int ooteaeg6=10; //ms Image pilt7=Toolkit.getDefaultToolkit().getImage("7saturn.jpg"); double nurk7=0; double raadius7=260; double samm7=0.018; int ooteaeg7=10; //ms Image pilt8=Toolkit.getDefaultToolkit().getImage("8uraan.jpg"); double nurk8=0; double raadius8=300; double samm8=0.019; int ooteaeg8=10; //ms Image pilt9=Toolkit.getDefaultToolkit().getImage("9neptuun.jpg"); double nurk9=0; double raadius9=340; double samm9=0.021; int ooteaeg9=10; //ms Image pilt10=Toolkit.getDefaultToolkit().getImage("10pluto.jpg"); double nurk10=0; double raadius10=380; double samm10=0.01; int ooteaeg10=10; //ms public p2ikesesysteem(){ add(tf); tf.addActionListener(this); new Thread(this).start(); } public void joonista(){ if(malupilt!=null){ //!= ei = nulliga Graphics g=malupilt.getGraphics(); g.setColor(Color.black); g.fillRect(0, 0, getSize().width, getSize().height);//tausta kohta käiv värk int keskx=getSize().width/2; //keskx ja kesky on ristküliku keskpunkti kordinaadid int kesky=getSize().height/2; double arv=Double.parseDouble(tf.getText().trim()); samm4=arv; //samm2=arv /*----------------- M A A ------------------------*/ g.drawImage(pilt4, keskx+(int)(raadius4*Math.cos(nurk4))-15,//pool pildi laiusest, kesky+(int)(raadius4*Math.sin(nurk4))-15, 30, 30, this ); /*----------------- P Ä I K E ---------------------*/ g.drawImage(pilt1, keskx-23, kesky-23, 46, 46, this ); /*----------------- M E R K U U R ----------------*/ g.drawImage(pilt2, keskx+(int)(raadius2*Math.cos(nurk2))-10, kesky+(int)(raadius2*Math.sin(nurk2))-10, 20, 20, this ); /*----------------- V E E N U S ------------------*/ g.drawImage(pilt3, keskx+(int)(raadius3*Math.cos(nurk3))-13, kesky+(int)(raadius3*Math.sin(nurk3))-13, 26, 26, this ); /*----------------- M A R S ----------------------*/ g.drawImage(pilt5, keskx+(int)(raadius5*Math.cos(nurk5))-11, kesky+(int)(raadius5*Math.sin(nurk5))-11, 22, 22, this ); /*----------------- J U P I T E R -----------------*/ g.drawImage(pilt6, keskx+(int)(raadius6*Math.cos(nurk6))-20, kesky+(int)(raadius6*Math.sin(nurk6))-20, 40, 40, this ); /*----------------- S A T U R N -------------------*/ g.drawImage(pilt7, keskx+(int)(raadius7*Math.cos(nurk7))-19, kesky+(int)(raadius7*Math.sin(nurk7))-19, 38, 38, this ); /*----------------- U R A A N ---------------------*/ g.drawImage(pilt8, keskx+(int)(raadius8*Math.cos(nurk8))-18, kesky+(int)(raadius8*Math.sin(nurk8))-18, 36, 36, this ); /*----------------- N E P T U U N -----------------*/ g.drawImage(pilt9, keskx+(int)(raadius9*Math.cos(nurk9))-16, kesky+(int)(raadius9*Math.sin(nurk9))-16, 33, 33, this ); /*----------------- P L U T O ---------------------*/ g.drawImage(pilt10, keskx+(int)(raadius10*Math.cos(nurk10))-15, kesky+(int)(raadius10*Math.sin(nurk10))-15, 30, 30, this ); nurk4=nurk4+samm4;//MAA if(nurk4>2*Math.PI)nurk4-=2*Math.PI; nurk2=nurk2+samm2;//MERKUUR if(nurk2>2*Math.PI)nurk2-=2*Math.PI; nurk3=nurk3+samm3;//VEENUS if(nurk3>2*Math.PI)nurk3-=2*Math.PI; nurk5=nurk5+samm5;//MARS if(nurk5>2*Math.PI)nurk5-=2*Math.PI; nurk6=nurk6+samm6;//JUPITER if(nurk6>2*Math.PI)nurk6-=2*Math.PI; nurk7=nurk7+samm7;//SATURN if(nurk7>2*Math.PI)nurk7-=2*Math.PI; nurk8=nurk8+samm8;//URAAN if(nurk8>2*Math.PI)nurk8-=2*Math.PI; nurk9=nurk9+samm9;//NEPTUUN if(nurk9>2*Math.PI)nurk9-=2*Math.PI; nurk10=nurk10+samm10;//PLUTO if(nurk10>2*Math.PI)nurk10-=2*Math.PI; this.getGraphics().drawImage(malupilt, 0, 0, this); } } public void run(){ while(veel){ try{ joonista(); Thread.sleep(ooteaeg4); Thread.sleep(ooteaeg2); // Thread.sleep(ooteaeg3); ??? } catch(Exception e){e.printStackTrace();} } } public void update(Graphics g){ } public void actionPerformed(ActionEvent e){//Enterivajutus kutsub välja alamproge liiguta /*--MÄLUPILT---*/ samm4=Double.parseDouble(tf.getText().trim()); malupilt=new BufferedImage(//joonistab mällu ja toob sealt getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); Graphics malug=malupilt.createGraphics(); /*---MÄLUPILT---*/ if(e.getSource()==tf)joonista(); } public static void main(String argumendid[]){//käivitab proge Frame f=new Frame(); f.add(new p2ikesesysteem()); f.setSize(900, 750); f.setVisible(true); } }