如何在JLabel中获取图像的X,Y坐标
问题描述:
我将地图图像放置为JLabel
的图标.
我正在使用以下代码来获取单击鼠标的位置的X,Y坐标.
我已将此代码放在JLabel
的MouseClick事件中.
I have an image of a map placed as the icon of a JLabel
.
I am using following code to get the X,Y coordinates of the location where the mouse is clicked.
I have put this code in the MouseClick event of the JLabel
.
Point point = MouseInfo.getPointerInfo().getLocation();
double X = point.getX();
double Y = point.getY();
,但是坐标取决于JFrame
表单的位置.如果移动表格,则坐标会更改.
but the coordinates depend on the location of the JFrame
form. If the form is moved the coordinates change.
反正我可以冻结JFrame
吗?
或者
无论如何,我可以将图像的一个角设为0,0并获得相对于该角的其他坐标吗? (这样我就可以计算出实际坐标)
Is there anyway I can freeze the JFrame
?
Or
Is there anyway I can get a corner of the image as 0,0 and get the other coordinates relative to that? (So I can calculate the actual coordinates)