ljukk

automatickaRampa

May 10th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1.  
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.Timer;
  5.  
  6. /*
  7.  * To change this license header, choose License Headers in Project Properties.
  8.  * To change this template file, choose Tools | Templates
  9.  * and open the template in the editor.
  10.  */
  11.  
  12. /**
  13.  *
  14.  * @author sused
  15.  */
  16. public class RampaAutomaticka extends Rampa implements ActionListener{
  17.    
  18.     private Timer t;
  19.     private boolean goUp;
  20.  
  21.     public RampaAutomaticka() {
  22.    
  23.         t = new Timer(100, this);
  24.         goUp = true;
  25.        
  26.     }
  27.    
  28.     public void goUp() {
  29.         goUp = true;
  30.         t.start();
  31.     }
  32.    
  33.     public void goDown() {
  34.         goUp = false;
  35.         t.start();
  36.     }
  37.    
  38.     public void Stop() {
  39.         t.stop();
  40. }
  41.  
  42.     @Override
  43.     public void down() {
  44.         if (y1 >= y2) t.stop();
  45.         x1-=2;
  46.         y1+=2;
  47.      
  48.       repaint();
  49.     }
  50.  
  51.     @Override
  52.     public void up() {
  53.         if (x1 >= x2) t.stop();
  54.         x1+=2;
  55.         y1-=2;
  56.      
  57.       repaint();
  58.     }
  59.    
  60.  
  61.     @Override
  62.     public void actionPerformed(ActionEvent e) {
  63.       if (goUp)  
  64.         up();
  65.       else
  66.           down();
  67.     }  
  68. }
Add Comment
Please, Sign In to add comment