gpt4 book ai didi

Java 检查 MouseReleased 位置是否在两点之间

转载 作者:行者123 更新时间:2023-11-29 05:24:38 26 4
gpt4 key购买 nike

我有一个游戏,您可以在其中单击一个面板,是的,该面板正在获取操作命令(通过在我单击该面板时打印文字进行测试)。如何检查 Point MosPos = MouseInfo.getPointerInfo().getLocation(); 如果在两点之间。

@Override
public void mouseReleased(MouseEvent event) {
if (event.getSource().equals(panel)) {
Point MosPos = MouseInfo.getPointerInfo().getLocation();
if (MosPos >= new Point(0, 0) && MosPos <= new Point(100, 100)) {
System.out.println("working.");
}
}
}

有什么建议吗?

最佳答案

就这样

int x = event.getX();
int y = event.getY();

如果你想要一个点:

Point p = event.getPoint();

然后比较:

int start = 0;
int end = 100;

if(x >= start && x <= end &&
y >= start && y <= end)
System.out.println("working");

关于Java 检查 MouseReleased 位置是否在两点之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23141057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com