Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

probably a dumb question, but I cant figure it out....

Thread view: 
Justin - 05 Oct 2006 23:31 GMT
I have implemented a mouse listener in a class that extends a JDialog.
I added a JLabel that contains a graphic.  When the user clicks on the
JLabel, the mouse clicked method should trigger a method that does
something with the coordinates.  However, when I do click, I get a null
pointer exception.  It goes to the line where i assign the variable

int xCoor = getMousePosition().x;

however, if i make xCoor a point, that is fine.  However again, if I
were try to copy either the x-coordinate or the y coordinate into an
int variable, I will get a null pointer.  Myself, being a hella noob,
cannot figure this out.

Thanks for any help....
Manish Pandit - 05 Oct 2006 23:44 GMT
getMousePosition() should not be in your listener. In the listener, you
need to do a event.getPoint() which will be relative to your source
component. You can use translatePoint() to translate it based on any
other component.

getMousePosition() will return null if the mouse is clicked outside the
component in which you are calling getMousePosition() - I believe that
is the reason for your NPE.

If this doesnt help, do paste your listener code.

-cheers,
Manish
Justin - 09 Oct 2006 01:40 GMT
works like a charm.  thank you very much

> getMousePosition() should not be in your listener. In the listener, you
> need to do a event.getPoint() which will be relative to your source
[quoted text clipped - 9 lines]
> -cheers,
> Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.