hikespect

Podar2

Dec 16th, 2019
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package newyear;
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class Podar {
  8.  
  9. public Image img;
  10. public int x,y;
  11. public Boolean act;
  12. Timer timerUpdate;
  13.  
  14. public Podar(Image img)
  15. {
  16.     timerUpdate = new Timer(500, new ActionLitener()) {
  17.     public void actionPerformed(ActionEvent e) {
  18.         down();
  19.        
  20.     }
  21. };
  22.    
  23. this.img = img;
  24. act=false;
  25. }
  26.     public void start()
  27.     {
  28.         timerUpdate.start();
  29.         y = 0;
  30.        
  31.         x=(int)(Math.random()*700);
  32.         act=true;
  33.     }
  34.     public void down()
  35.     {
  36.         if(act==true)
  37.         {
  38.             y+=6;
  39.         }
  40.         if((y+img.getHeight(null))>=470);
  41.         {
  42.         timerUpdate.stop();
  43.         }
  44.     }
  45.     public void draw(Graphics gr)
  46.     {
  47.         if(act==true)
  48.         {
  49.             gr.drawImage(img,x,y,null);
  50.         }
  51.     }
  52.     }
Add Comment
Please, Sign In to add comment