aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How can i use mouse to click on an image and draw a point after i clicked ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How can i use mouse to click on an image and draw a point after i clicked ?" Watch "How can i use mouse to click on an image and draw a point after i clicked ?" New topic
Author

How can i use mouse to click on an image and draw a point after i clicked ?

motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
How can i use mouse to click on an image and draw a point(example a red dot) after i clicked ?
I also need to save and show the coordinate where i clicked.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Moving to our UI forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
in your mousePressed/Clicked code:
you update some variables with the coordinates from the mouseEvent
call repaint()

in paintComponent:
draw the red dot using the info from the (above) variables

> I also need to save and show the coordinate where i clicked.
save where? in a file - you should be able to do that
show where? a JLabel? - just update the label's text with the coords (can be done from mousePressed/Clicked)
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
Michael Dunn wrote:in your mousePressed/Clicked code:
you update some variables with the coordinates from the mouseEvent
call repaint()

in paintComponent:
draw the red dot using the info from the (above) variables

> I also need to save and show the coordinate where i clicked.
save where? in a file - you should be able to do that
show where? a JLabel? - just update the label's text with the coords (can be done from mousePressed/Clicked)


I still cannot draw a red dot on image after i clicked .... Can tell me where i supposed to add the coding and what coding suppose to add ?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2172
    
    7
Custom Painting Approaches shows a couple of different ways. It draws a Rectangle but you can change it to paint a dot. It draws on a JPanel but you can change it to draw on a JLabel with an ImageIcon.
motress zlting
Ranch Hand

Joined: Jan 10, 2010
Posts: 55
Rob Camick wrote:Custom Painting Approaches shows a couple of different ways. It draws a Rectangle but you can change it to paint a dot. It draws on a JPanel but you can change it to draw on a JLabel with an ImageIcon.


But, for first time i clicked on image, it get coordinate and draw a red dot, for the second times after i clicked, the first dot should remain at there...
I don't don know where should i place those coding......
After i moved my mouse, that dot dissapear....
Help me take a look at my coding....Thanks...

pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
If you need to draw more than one "dot" then you need to use a collection of "dots" or perhaps Points. Consider creating an ArrayList<Point> and adding a Point to this list each time the mouse is pressed. Then in your paintComponent method iterate through the list of Points painting them as you go.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i use mouse to click on an image and draw a point after i clicked ?