Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Draw a point on an image in java  RSS feed

 
Lara Gh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i use mouse to click on an image and draw a point after i click. This is the code below it draws a point on the panel but not on the image can you please help me?


and this is the main class
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code don't forget to use the "Code tags" so the code retains its formatting. Please edit your posting to fix this. You may need to recopy the code since you probably have lost all the original formatting.

Read the section from the Swing tutorial on A Closer Look at the Painting Mechanism. When the paint() method is invoked the following 3 methods are invoked in order:

•protected void paintComponent(Graphics g)
•protected void paintBorder(Graphics g)
•protected void paintChildren(Graphics g)

So your circles are painted on the panel, but then the label is painted on top of the panel.

So if you want your circles to be painted on top of any component added to the panel, you need to override the paint() method, not the paintComponent() method.
 
Tony Docherty
Bartender
Posts: 3268
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick wrote:
So if you want your circles to be painted on top of any component added to the panel, you need to override the paint() method, not the paintComponent() method.

Remembering to call super.paint() as the first line of the method body.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!