Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with MouseListener and JComponent

807603Feb 15 2008 — edited Feb 17 2008
Hi, I am making a "game" where I have a 2D map made of png images and I want to enable the user to click on each separate image that makes together a whole map. I figured out how to do that in the JPanel when I tried out if the coordinates of the mouseevent overlay any of the used images, but I would like to handle the mouseevent for each of the image separately.

I created the class Region extends JComponent implements MouseListener. This class draws the ImageIcon. I used setBounds to set the JComponent to the ImageIcon location and size and I didn't forget to add the mouseListener, but I still can get no response from any mouse clicking efforts. I guess there is still something I must do in order to get the JComponent and MouseListener working, but I dunno what. Thanks for advice.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2008
Added on Feb 15 2008
11 comments
1,627 views