import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Vaiad1 extends Applet implements ActionListener, Runnable{ double maapind=250; double vaiay=150; double haamriy=100; double haamrikorgus=20; double haamrilaius=20; double haamrisamm=0; double kraananooly=50; double loomisx=150; double kraanax=100; double noolepikkus=100; Button nupp=new Button("Löö"); boolean veel=true; int seisund=-1; //-1 ootel, 0-kukub, 1-kukub koos vaiaga public Vaiad1(){ add(nupp); new Thread(this).start(); nupp.addActionListener(this); } public void paint(Graphics g){ g.drawLine((int)kraanax, (int)maapind, (int)kraanax, (int)kraananooly); g.drawLine((int)kraanax, (int)kraananooly, (int)(kraanax+noolepikkus), (int)kraananooly); g.drawLine((int)(loomisx+haamrilaius/2), (int)kraananooly, (int)(loomisx+haamrilaius/2), (int)haamriy); g.fillRect((int)loomisx, (int)haamriy, (int)haamrilaius, (int)haamrikorgus); g.drawRect((int)loomisx, (int)vaiay, (int)haamrilaius, (int)(maapind-vaiay)); } void liigu(){ if(seisund==0 && haamriy+haamrikorgus=vaiay){seisund=1;} if(haamriy>maapind){veel=false;} } else if(seisund==1){ haamriy=haamriy+5; vaiay=haamriy+haamrikorgus; seisund=2; haamrisamm=-1; } else if(seisund==2){ if(haamriy>100){haamriy+=haamrisamm;} else{ seisund=0; } } } public void run(){ while(veel){ liigu(); repaint(); try{Thread.sleep(100);} catch(Exception ex){} } } public void actionPerformed(ActionEvent e){ seisund=0; haamriy=100; haamrisamm=0; } public static void main(String[] arg){ Frame f=new Frame(); f.add(new Vaiad1()); f.setSize(300, 300); f.setVisible(true); } }