public boolean isSelected(int mousex, int mousey)
    {
        double a, b, c, h, g;

        a = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        b = Math.sqrt((x1 - mousex) * (x1 - mousex) + (y1 - mousey)
                * (y1 - mousey));
        c = Math.sqrt((mousex - x2) * (mousex - x2) + (mousey - y2)
                * (mousey - y2));

        h = a / 2 - (b * b) / (2 * a) + c * c / (2 * a);

        g = Math.sqrt(c * c - h * h);
        if (g < 10
                && (mousex > x1 - 10 && mousex < x2 + 10 || mousex < x1 + 10
                        && mousex > x2 - 10)
                && (mousey > y1 - 10 && mousey < y2 + 10 || mousey < y1 + 10
                        && mousey > y2 - 10))
            return true;
        return false;
    }