I have a bunch of rectangles on a

JPanel, and lines that connect some of the rectangles together. It represents a network map. I wrote the actionListener that handles the clicks on the rectangles. I simply map the x-y coordinates along with the height and width, then grab the points where the click occurred. Now I need a way to figure out if the click was on the lines that connect the rectangles. (Many of these lines are not vertical or horizontal, they make a diagonal across the screen. I am thinking I have to compute all the points the line hits by finding its slope of the line. Is there an easier way to do this? Any help would be greatly appreciated.