Depending on the contrasting of the colors you might be able to scan an image and find a rectangle.

Yes it would.
There are some methods in Graphics2D that might be of interest to you for drawing.