Say I have a 400 x 400 JPanel in the middle of a 500 x 500 JFrame. The JPanel has string drawn to it that prints out the mouse coordinates. If my mouse were placed exactly in the middle of the JFrame, the string should read (200, 200). What is the best way to accomplish this?
I've used java.awt.MouseInfo but that has only helped me get the position of the mouse relative to the entire screen. [ March 23, 2006: Message edited by: Brandon Tom ]
Brandon Tom, SCJP, MCP<br />Programmer/Graphic Designer<br /><a href="http://mailto:tombrand@hawaii.edu" target="_blank" rel="nofollow">tombrand@hawaii.edu</a>
Add a MouseListener to the JPanel. Implements the MouseEntered method. This will have a parameter for the Mouse Event from which you will get the Mouse Co ordinates relative to the JPanel. hope that helps, Please get back to me in case you have doubts