hello... everyone! i have included graphics over Map like a popup menu, but now i need to provide a mouse click action over the graphic. Is it possible...??

let me explain properly. i have given city details over open street maps by using graphics2D, now i need to give a clickable link such that when i click that round rectangle (of graphics i.e the popup menu) then it must take me to the given website link.

i can do it from a JLabel, but i cannot able to do it from a graphics. i cannot add JLabels to the graphics. if it can be added then the problem can be solved. please give me some valuable suggestion regarding my problem. Any help will highly be appreciated. Thanks in advance.

Given that you are able to take current mouse coordinates on mouse click, you already knows location of the city ([x1,y1][x2,y2]) on mouse click get mouse coordinates and work out if

  1. mouse over any of the cities
  2. which city
  3. provide it with the link

Thank you for your reply. But can you explain me in coding.... i cannot able to proceed.

Yaa..! i did it. but there is one problem. if i zoom in/out then the coordinate position changes so then it creates a problem... is there any other way to solve the problem? please share with me if anyone have any idea.

You need a way to change/map your city detail x,y locations as you zoom or position the screen.
Perhaps you can find an algorithm by taking paper and pencil and drawing a rectangle for the original view. Find an x,y on that and then zoom in by drawing a new rectangle within the old one and then see where the x,y is in the new rectangle. The new rectangle would have the same width and height in pixels as the original one so the old pixels would be stretched.

Yaa..! i did it. but there is one problem. if i zoom in/out then the coordinate position changes so then it creates a problem... is there any other way to solve the problem? please share with me if anyone have any idea.

Then you are trying to re-invent the wheel. Google Maps already have extensive Java API and there are many libraries that brings even more customization

This article has been dead for over six months. Start a new discussion instead.