Ball.javaimport java.awt.*;
public class Ball
{
double px, py;
double vx, vy;
double mass;
int radius;
Color color;
Ball()
{
color = new Color(255,0,0);
px = 50;
py = 50;
vx = 7;
vy = 5;
set_radius(17);
}
Ball(int px, int py, int vx, int vy, Color color)
{
this.px = px;
this.py = py;
this.vx = vx;
this.vy = vy;
this.color = color;
set_radius(17);
}
void set_radius(int r)
{
radius = r;
mass = r*r;
}
public String toString()
{
String str = "("+px+", "+py+") " + color;
return str;
}
public void move()
{
px += vx;
py += vy;
}
public void move(double delta)
{
px += vx*delta;
py += vy*delta;
}
public void draw(Graphics g)
{
g.setColor(color);
g.fillOval((int)(px-radius), (int) (py-radius), (int)2*radius, (int)2*radius);
}
}
Maintained by John Loomis, updated Sun Feb 17 18:43:45 2013