import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.LinkedList; public class KukkuvPall4 extends Applet implements MouseListener, Runnable{ int r=10; double koef=10; //10 punkti=1 meeter int maapind=200; LinkedList pallid=new LinkedList(); Image taust=Toolkit.getDefaultToolkit().getImage("taust.gif"); Image pall=Toolkit.getDefaultToolkit().getImage("lill1.gif"); Image puhver; int ex(double ox){ return (int)(ox*koef); } int ey(double oy){ return (int)(maapind-oy*koef); } double ox(int ex){ return ex/koef; } double oy(int ey){ return (maapind-ey)/koef; } public KukkuvPall4(){ addMouseListener(this); new Thread(this).start(); } public void paint(Graphics g){ if(puhver==null){ puhver=createImage(getWidth(), getHeight()); } Graphics piltg=puhver.getGraphics(); piltg.drawImage(taust, 0, 0, this); for(int i=0; i2){ repaint(); try{Thread.sleep(100);}catch(Exception e){} } } public void mousePressed(MouseEvent e){ maapind=getHeight(); pallid.add(new Pall(ox(e.getX()), oy(e.getY()))); } public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseExited(MouseEvent e){} public static void main(String[] argumendid){ Frame f=new Frame(); f.add(new KukkuvPall4()); f.setSize(200, 200); f.setVisible(true); } class Pall{ long algaeg=System.currentTimeMillis(); double ax, ay; double tk; //kukkumisaeg final double g=9.8; public Pall(double ux, double uy){ ax=ux; ay=uy; tk=Math.sqrt(ay*2/g); } double kysiX(){return ax;} double kysiY(){ double t=(System.currentTimeMillis()-algaeg)/1000.0; int tehtudPorgeteArv=(int)(t/(2*tk)); t=t-tehtudPorgeteArv*2*tk; if(t<=tk){ return ay-9.8*t*t/2; } return ay-9.8*(2*tk-t)*(2*tk-t)/2; } } }