Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- public class Ball
- {
- public int x, y, r, maxx, maxy;
- //public static needed to be referenced in context
- public static int dx = 1, dy = 1;
- public Color c;
- public Ball(int X, int Y, int R, Color C)
- {
- x = X;
- y = Y;
- r = R;
- c = C;
- }
- public void draw(Graphics g)
- {
- g.setColor(c);
- g.fillOval(x-r, y-r, 2*r, 2*r);
- }
- public void move()
- {
- x = x + dx;
- y = y + dy;
- if(x > maxx)
- dx=-dx;
- if(x <= 0)
- dx=-dx;
- if(y > maxy)
- dy=-dy;
- if(y <= 0)
- dy=-dy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement