Plotting dots on Canvas and adding/removing them

Posted on 2006-06-14
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?
Question by:ibo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 86

Expert Comment

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

Author Comment

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.
LVL 86

Accepted Solution

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:

See the contains method

Author Comment

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.
LVL 86

Expert Comment

ID: 16909272

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


Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 77
ejb on wildfly 5 63
mysql jsp example issue 32 96
American Express @Work site and Java 4 95
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

738 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