i find physics confusing in general i am trying to create a simulation not far off the same as shown here for my university project i have the ball moving using angle and velocity by doing 


double scale_x=cos(angle);
double scale_y=sin(angle);
double v_x = (speed * scale_x);
double v_y = (speed * scale_y);

now i am looking to get the ball to bounce off the sides of the JPannel on collision also collision detection with two balls.
however i find it hard to understand how we are getting the balls to collide here and collision with the JPannel.