Results 1 to 14 of 14
Thread: Applet with images
- 05-08-2012, 03:00 PM #1
Member
- Join Date
- Dec 2011
- Location
- Belgium
- Posts
- 25
- Rep Power
- 0
Applet with images
Hey I have an applet with several images on a canvas.
I want to know on wich image I have clicked and then be able to drag that image. How can I do this?
I'm already aware of the drag en drop of a mouseMotionAdapter and a mouseMotionListener. Wich I am using in my package. I just don't know how my application can recognize the image I clicked on.
- 05-08-2012, 03:32 PM #2
Re: Applet with images
Do you know the location of each image? Just check the mouse location against the bounds of each image.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-08-2012, 03:33 PM #3
Re: Applet with images
A mouse listener would help you find where the mouse was clicked.how my application can recognize the image
Then it depends on how the images are being displayed.If you don't understand my response, don't ignore it, ask a question.
- 05-08-2012, 04:07 PM #4
Member
- Join Date
- Dec 2011
- Location
- Belgium
- Posts
- 25
- Rep Power
- 0
- 05-08-2012, 04:11 PM #5
Re: Applet with images
The event passed to the listener has the location of the mouse click that you can get by calling a method.
Given the x,y of the click and the location of the images, you can search the images' locations to see which contains the location of the mouse click.If you don't understand my response, don't ignore it, ask a question.
- 05-08-2012, 04:16 PM #6
Member
- Join Date
- Dec 2011
- Location
- Belgium
- Posts
- 25
- Rep Power
- 0
Re: Applet with images
Do you have an example of this? I do have a mouseClicked method that gives me the exact position of the mouse. But I still don't get how you can compare this with all of the x,y coordinates the image overlaps on the canvas. Or isn't that nescessary?
- 05-08-2012, 04:18 PM #7
Re: Applet with images
If the locations of the images are in a list, use a loop to test the mouse's location against the location of each image in the list.how you can compare this with all of the x,y coordinates the imageIf you don't understand my response, don't ignore it, ask a question.
- 05-08-2012, 04:50 PM #8
Member
- Join Date
- Dec 2011
- Location
- Belgium
- Posts
- 25
- Rep Power
- 0
Re: Applet with images
And if I don't know the location of the images. How do I get the location of the images. I placed the images on the applet myself (mvc) view so in theory I know them, but just wondering.
- 05-08-2012, 04:55 PM #9
Re: Applet with images
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 05-08-2012, 04:59 PM #10
Member
- Join Date
- Dec 2011
- Location
- Belgium
- Posts
- 25
- Rep Power
- 0
Re: Applet with images
Yes but all 32 images are drown on a canvas (the view extends canvas) so canvas is the object you are referring to. Still a simple example would be very helpfull to understand this better.
- 05-08-2012, 05:10 PM #11
Re: Applet with images
If you define a rectangle that maps where the image is, you can use the rectangle class's contains() method. Something like this:
if(imagesRect[ix].contains(mouseClickPt)) {
// click was in this image
}If you don't understand my response, don't ignore it, ask a question.
- 05-08-2012, 06:52 PM #12
Re: Applet with images
Moved from Advanced Java
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-09-2012, 02:04 PM #13
Member
- Join Date
- Dec 2011
- Location
- Belgium
- Posts
- 25
- Rep Power
- 0
- 05-09-2012, 02:08 PM #14
Similar Threads
-
Images in applet
By Ranu in forum New To JavaReplies: 2Last Post: 07-09-2010, 05:05 AM -
Putting Applet on web with images
By Peetahzee in forum New To JavaReplies: 1Last Post: 04-18-2010, 08:35 PM -
[Applet] Clicking images & moving them.
By Perfectworld in forum Java AppletsReplies: 17Last Post: 01-16-2010, 08:09 AM -
Extract images from Java applet
By User01 in forum Java AppletsReplies: 2Last Post: 12-23-2009, 06:44 AM -
Applet with Images in Browser
By baron in forum EclipseReplies: 0Last Post: 09-20-2009, 10:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks