Array Detection
I have an array of 5 images. I want to be able to click on each of the images, no matter where they are placed in an applet, but have it so that it only registers if you click within the image, not the surrounding area. How exactly would I go about programming it so that I could make a "universal" code where I wouldn't have to program each box separately
[364 byte] By [
OHarlowea] at [2007-11-26 12:21:10]

# 2
Right, I've implemented MouseListener. The actual problem I'm having is I'm not sure how to go about programming it so that you can actually click the sprite without having to check each individual box. I have variables that retrieve the x and y positions whenever you click. I'm not sure how to compare that to the 'group' instead of each box.
# 4
> Right, I've implemented MouseListener. The actual
> problem I'm having is I'm not sure how to go about
> programming it so that you can actually click the
> sprite without having to check each individual box. I
> have variables that retrieve the x and y positions
> whenever you click. I'm not sure how to compare that
> to the 'group' instead of each box.
Use a collision detection algorithm to determine which sprite(s) have been clicked. All you need to know is the coordinates of the sprites and their corresponding dimensions.
If you use a JLabel to display the image (as opposed to drawing the image yourself), you can simply add the MouseListener to the JLabel.