• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Application: drawing points/lines/circles

SnoopCat

Senior member
I need to write a small Java Application (not applet), that plot points, make lines, and draw circles over an image file.
The drawn points, lines, circles does not need to permanently change the image file.

I have have been able to make the image appear onto a JLabel and put the JLabel onto a JPanel. However, when I try to draw lines, the lines seem to appear behind the image. Any tips?
 
I've done something like this before.

What I did was use a collection object to keep track of a set of generic Shape objects. Each shape object contained a draw() method that would render that shape using a Graphics2D canvas. On the JPanel's paintComponent method, I would loop through each of the Shapes in the collection object and draw them. As long as you use a collection object that preserves ordering, you can maintain and manipulate the order in which the shapes are drawn.
 
Back
Top