title: Drawing things in the right order, Java
body: <p>I'm in the process of writing a "Paint" application in Java consisting of rectangular nodes and undirected edges. The problem is that the beginning of the edge is in the center of the rectangle the edge is connected to, and the end of the edge is in the center of the other rectangle this edge is connected to.</p>
  
  <p>To avoid drawing the intersection between the rectangle and the edge, I draw edges first and nodes afterwards, so that they are placed on top of the edges, thus hiding the intersection.</p>
  
  <p>The problem arises when another node, which does not correspond to that edge is placed along the edge. In this scenario, because edges are drawn first, the node appears on top of the edge. However, that is not what I want. I want the edge to show on top of the node.</p>
  
  <p>Images:
   <a href="http://i.stack.imgur.com/MzVFY.png" rel="nofollow">how it is</a> and <a href="http://i.stack.imgur.com/AVyUT.png" rel="nofollow">how it should be</a></p>
  
  <p>The most comprehensive way I can think of to fix this would be to draw nodes first and afterwards draw the edges avoiding the intersections of the edge with the two nodes it is connected to. However that is difficult to do on paper because I draw edges using <code>drawLine</code>, and I do not have the possibility to check for intersections.</p>
  
  <p>This is why I draw edges first, but then the problem I mentioned arises. Any ideas?</p>