Advertisement
Guest User

Untitled

a guest
May 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.awt.Graphics;
  2.  
  3.  
  4. @SuppressWarnings("serial")
  5. public class Anim6 extends AnimationPanel
  6. {
  7.     private static final float SPEED1=80, SPEED2=40;
  8.     private static final int SIZE=50;
  9.    
  10.     private double x,y;
  11.     private int smer1=1;
  12.  
  13.     @Override
  14.     protected boolean step(double elapsedTime)
  15.     {
  16.         x+=elapsedTime*SPEED1*smer1;
  17.         y+=elapsedTime*SPEED2*smer1;
  18.        
  19.         if(x<=0){
  20.             x=0;
  21.             smer1*=-1;
  22.         }else if(x>=getWidth()-SIZE){
  23.             x=getWidth()-SIZE;
  24.             smer1*=-1;
  25.        
  26.         }
  27.         if(y<=0){
  28.             y=0;
  29.             smer1*=-1;
  30.         }
  31.         else if(y>=getHeight()-SIZE){
  32.             y=getHeight()-SIZE;
  33.             smer1*=-1;
  34.         }
  35.         return true;
  36.     }
  37.     @Override
  38.     protected void draw(Graphics g) {
  39.         g.drawOval((int)x, (int)y, SIZE, SIZE);
  40.        
  41.     }
  42.  
  43.    
  44.     public static void main(String[] args)
  45.     {
  46.         new Anim6().run(400, 200, "Zad 1", true);
  47.     }
  48.  
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement