import java.awt.*; import java.lang.*; import java.applet.*; import java.awt.event.*; public class Roller extends Applet implements ActionListener{ TextField r1suur = new TextField("30", 5); TextField r2suur = new TextField("5", 5); TextField kiirus = new TextField("30", 5); TextField raskkiir = new TextField("2", 5); TextField t1 = new TextField("Ratta suurus", 11); TextField t2 = new TextField("Kivi suurus", 11); TextField t3 = new TextField("Ratta kiirus", 11); TextField t4 = new TextField("Raskuskiirendus", 11); Button nupp = new Button("Valmis"); static int rad = 30; static int rad2 = 5; static int v = 30; static int rk = 2; int x, y; int v0, vt0; int temp; public void init(){ add(r1suur); add(t1); t1.setEnabled(false); add(r2suur); add(t2); t2.setEnabled(false); add(kiirus); add(t3); t3.setEnabled(false); add(raskkiir); add(t4); t4.setEnabled(false); add(nupp); nupp.addActionListener(this); } public void paint(Graphics g){ int i = 0; g.drawLine(0,300,600,300); g.drawOval(590-2*rad, 300-2*rad, 2*rad, 2*rad); temp = (int)Math.sqrt((rad+rad2)*(rad+rad2)-(rad-rad2)*(rad-rad2)); g.drawOval(590-rad-temp-rad2, 300-2*rad2, rad2*2, rad2*2); x = 590-rad-temp; y = 300-rad2; fly(getGraphics()); r1suur.setLocation(180,310); r2suur.setLocation(180,335); kiirus.setLocation(350,310); raskkiir.setLocation(350,335); nupp.setLocation(430,320); t1.setLocation(80, 310); t2.setLocation(80, 335); t3.setLocation(250, 310); t4.setLocation(250, 335); } public void fly(Graphics g) { int i = 0, xt = 0, yt = 0, x1, y1, m; vt0 = v*temp/(rad+rad2); v0 = v*(rad-rad2)/(rad+rad2); x1 = x-xt; y1 = y-yt; for (i = 0; i < x; i++){ //s=v0*t xt = Math.round(v0*(i/10)); //s=v0*t-(gt^2)/2 yt = Math.round((float)(vt0*(i/10) - Math.pow((i/10),2)*rk/2)); g.drawLine(x - xt, y - yt, x1, y1); x1 = x-xt; y1 = y-yt; } } public void actionPerformed(ActionEvent e){ Integer tmp = new Integer(1); rad = tmp.parseInt(r1suur.getText()); rad2 = tmp.parseInt(r2suur.getText()); v = tmp.parseInt(kiirus.getText()); rk = tmp.parseInt(raskkiir.getText()); repaint(); } }