Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics;
- @SuppressWarnings("serial")
- public class Anim6 extends AnimationPanel
- {
- private static final float SPEED1=80, SPEED2=40;
- private static final int SIZE=50;
- private double x,y;
- private int smer1=1;
- @Override
- protected boolean step(double elapsedTime)
- {
- x+=elapsedTime*SPEED1*smer1;
- y+=elapsedTime*SPEED2*smer1;
- if(x<=0){
- x=0;
- smer1*=-1;
- }else if(x>=getWidth()-SIZE){
- x=getWidth()-SIZE;
- smer1*=-1;
- }
- if(y<=0){
- y=0;
- smer1*=-1;
- }
- else if(y>=getHeight()-SIZE){
- y=getHeight()-SIZE;
- smer1*=-1;
- }
- return true;
- }
- @Override
- protected void draw(Graphics g) {
- g.drawOval((int)x, (int)y, SIZE, SIZE);
- }
- public static void main(String[] args)
- {
- new Anim6().run(400, 200, "Zad 1", true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement