2 个解决方案
#1
if you means the screen, you can get screen
size by call Toolkit.getDefaultToolkit().getScreenSize();
Then in a mouse event, you can get current mouse
position, Comparing both.
if you mean a component. there is function
contains(int x, int y) can be used. this function
return true if point is inside, otherwise return
false.
MouseEvent.getX();
MouseEvent.getY();
size by call Toolkit.getDefaultToolkit().getScreenSize();
Then in a mouse event, you can get current mouse
position, Comparing both.
if you mean a component. there is function
contains(int x, int y) can be used. this function
return true if point is inside, otherwise return
false.
MouseEvent.getX();
MouseEvent.getY();
#2
不需要这么麻烦。用以下的方法很容易解决。
//将屏幕上的点转化为相对于Component c的坐标点
SwingUtilities.convertPointFromScreen(Point p, Component c);
//将相对于Component c的点转化为屏幕上的坐标点
SwingUtilities.convertPointToScreen(Point p, Component c);
//将屏幕上的点转化为相对于Component c的坐标点
SwingUtilities.convertPointFromScreen(Point p, Component c);
//将相对于Component c的点转化为屏幕上的坐标点
SwingUtilities.convertPointToScreen(Point p, Component c);
#1
if you means the screen, you can get screen
size by call Toolkit.getDefaultToolkit().getScreenSize();
Then in a mouse event, you can get current mouse
position, Comparing both.
if you mean a component. there is function
contains(int x, int y) can be used. this function
return true if point is inside, otherwise return
false.
MouseEvent.getX();
MouseEvent.getY();
size by call Toolkit.getDefaultToolkit().getScreenSize();
Then in a mouse event, you can get current mouse
position, Comparing both.
if you mean a component. there is function
contains(int x, int y) can be used. this function
return true if point is inside, otherwise return
false.
MouseEvent.getX();
MouseEvent.getY();
#2
不需要这么麻烦。用以下的方法很容易解决。
//将屏幕上的点转化为相对于Component c的坐标点
SwingUtilities.convertPointFromScreen(Point p, Component c);
//将相对于Component c的点转化为屏幕上的坐标点
SwingUtilities.convertPointToScreen(Point p, Component c);
//将屏幕上的点转化为相对于Component c的坐标点
SwingUtilities.convertPointFromScreen(Point p, Component c);
//将相对于Component c的点转化为屏幕上的坐标点
SwingUtilities.convertPointToScreen(Point p, Component c);