The original didn’t account for being outside the two points, so heres a revision:
boolean isPointOnLine( float px, float py, float ax, float ay, float bx, float by, float error )
{
float dx = bx - ax;
float dy = by - ay;
float len = Math.sqrt( dx*dx + dy*dy );
float rLen = 1.0f / len;
// Distance is '(B - A)(normalised) X (P - A)'
float d = (dx * (py - ay) - dy * (px - ax)) * rLen;
if( (d < error) && (d > -error) )
{
// Now use the dot product to determine distance down the line.
d = (dx * (px - ax) + dy * (py-ay)) * rLen;
if( (d >= 0.0f) && (d <= len) )
return true;
}
return false;
}
There are two stages to this now:
- Using the cross product.
The cross product of 2 vectors produces a third vector that is perpendicular to the two input vectors (A and B), and has magnitude AB sin theta, where theta is the angle between the two vectors. If one of these vectors (B) is a unit vector (1 unit long), then the result is A sin( theta ). This value is the distance of the point from the line.
As we are in 2 dimensions, the cross product ‘vector’ would be entirely up the z- axis, so we can skip most of the cross product and just use the ‘z component’:
(A x B)z = distance from line = Ax * By - Ay * Bx
If this distance is less than the error, we are along the line.
Step 2:
To test if we lie between pointA and pointB, we need the distance of the point along the line. This is done with the DOT product, which gives AB cos (theta).
(A . B) = distance along line - Ax * Bx + Ay * By
Google for ‘cross product’, ‘dot product’ and trigonometry to find more 
PS: Can someone set ‘code’ to use Courier or some other fixed-space font please?