Solved

Plotting dots on Canvas and adding/removing them

Posted on 2006-06-14
5
415 Views
Last Modified: 2010-03-31
I was able to create an applet with a canvas and an Image display over the canvas. I also created an interactive feature that lets me mark red dots over the canvas (on top of image). Now, I want to create a feature that also lets me remove an existing dot.. like how they do it in Flash editor, removing a vector graphics by highlighting or clicking it and pressing delete. Can anyone give me some techniques on how to do it?
0
Comment
Question by:ibo
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16909035
You need to keep a list of dots to be painted. Add a MouseListener and if one of the dots, say, is right-clicked, remove it from the list and call repaint
0
 
LVL 3

Author Comment

by:ibo
ID: 16909125
I already have a list of locations of the dots. The part missing is how to implement the "right-click to remove" feature. How do I go about that? Do I just read the location for a red pixel? I know it wont work because underneath is an image which can have any kind of picture/color. Also, the dot is not a 1x1 pixel, but can vary in size, ie. a filled circle with a radius of 5 pixels. Is there an exisiting technique how to implement this kind of problem? Im concerned with overlapping dots too.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 80 total points
ID: 16909138
What's underneath is immaterial. If the dots are not 1 pixel in diameter then you need to keep a record of their bounds. I suggest the following:

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/Shape.html

See the contains method
0
 
LVL 3

Author Comment

by:ibo
ID: 16909226
I think thats what im looking for.. to be able to determine that a marked point is inside the boundary of the dot.
hmm what if a location hits two (or more) intersecting dots? I guess Ill have to choose the latest dot plotted right?. Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16909272
:-)

>>I guess Ill have to choose the latest dot plotted right?. Thanks.

Possibly
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now