import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.io.*; public class Kann extends Applet implements ActionListener{ Button nupp=new Button(" Tulista "); TextField tf1= new TextField(); int x[]={200,250,255,200}; int y[]={160,100,105,180}; int n=4; double nu=30; double tuul=0; public Kann(){ add(nupp); add(tf1); nupp.addActionListener(this); } public void actionPerformed(ActionEvent e){ Graphics g=getGraphics(); g.drawOval(70,110,60,60); g.fillOval(70,110,60,60); g.setColor(Color.white); g.drawOval(80,120,40,40); g.fillOval(80,120,40,40); g.setColor(Color.black); g.drawRect(100,100,100,100); g.fillRect(100,100,100,100); g.drawPolygon(x,y,n); g.fillPolygon(x,y,n); tuul=Double.parseDouble(tf1.getText()); double nurk=Math.toRadians(nu); int vasakult=253; int ylalt=103; double x=0, y=0; double vgy=0; final double G=-9.8; double sammuaeg=0.1; double viskeKiirus=50; double viskeSammX=Math.cos(nurk)*viskeKiirus*sammuaeg; double viskeSammY=Math.sin(nurk)*viskeKiirus*sammuaeg; while(ylalt-(int)y<=200){ double uvgy=vgy+G*sammuaeg; double vahemaay=(vgy+uvgy)/2*sammuaeg; y=y+vahemaay+viskeSammY; x=x+viskeSammX-tuul/5; vgy=uvgy; g.setColor(Color.blue); g.drawOval(vasakult+(int)x, ylalt-(int)y, 10, 10); g.fillOval(vasakult+(int)x, ylalt-(int)y, 10, 10); try{Thread.sleep((int)(sammuaeg*1000));}catch(Exception ex){} g.setColor(getBackground()); g.drawOval(vasakult+(int)x, ylalt-(int)y, 10, 10); g.fillOval(vasakult+(int)x, ylalt-(int)y, 10, 10); } } public static void main(String argumendid[]){ Frame f=new Frame("Piisk"); f.add(new Kann()); f.setSize(500, 500); f.setVisible(true); f.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); } }); } }