Solved

Plotting dots on Canvas and adding/removing them

Posted on 2006-06-14
5
404 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

707 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

15 Experts available now in Live!

Get 1:1 Help Now