User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 397,845 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,429 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1876 | Replies: 2 | Solved
Reply
Join Date: Oct 2006
Location: Evanston IL
Posts: 132
Reputation: venomlash is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
venomlash's Avatar
venomlash venomlash is offline Offline
Junior Poster

Question Getting mouse coordinates from MouseListener

  #1  
Aug 28th, 2007
Is there any function in MouseListener that returns the x- and/or y-coordinates of the cursor relative to the origin of a JPanel which currently has the focus? ¡Ayúdenme, por favor!
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 2,639
Reputation: Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light Ezzaral is a glorious beacon of light 
Rep Power: 11
Solved Threads: 261
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Maven

Re: Getting mouse coordinates from MouseListener

  #2  
Aug 28th, 2007
The MouseEvent getX() and getY() methods will return the coordinates relative to the source of the event. If your panel is not that source, you will have to compute the coordinates yourself by adding them to the coordinates of the source (which also has getX() and getY() methods) within that panel. It just depends on the layering of your components and which is the source of the mouse event. This tutorial has more info if you need it:
http://java.sun.com/docs/books/tutor...nlistener.html
Reply With Quote  
Join Date: Oct 2006
Location: Evanston IL
Posts: 132
Reputation: venomlash is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
venomlash's Avatar
venomlash venomlash is offline Offline
Junior Poster

Re: Getting mouse coordinates from MouseListener

  #3  
Aug 28th, 2007
Thank you, Ezzaral. Helpful, concise, and 1337; just how the best answers are. Party on, dude.
Beware of the Rancor. I'm not kidding.
If it doesn't compile, try saying "By the power of MegaMan!!!" <this has kinda worked for me, actually...>
Scotland is NOT North Britain, Glasgow does NOT rhyme with "cow", and Robbie Burns is...well, if you don't already know who he was, you're kinda screwed.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 7:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC