- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个游戏,您可以在其中单击一个面板,是的,该面板正在获取操作命令(通过在我单击该面板时打印文字进行测试)。如何检查 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/
拖动鼠标后释放鼠标时是否应该调用 mouseReleased() 事件? 我需要调用 mouseReleased() 来重置 mouseDragged() 中使用的一些变量,但它似乎从未被调用。 最佳
我正在尝试做类似的事情:Swing - Get new component under mouseReleased 在一个窗口中,我有一些按钮,每个按钮上都有一个数字。例如 2 8 5 6。这将显示
我有一个游戏,您可以在其中单击一个面板,是的,该面板正在获取操作命令(通过在我单击该面板时打印文字进行测试)。如何检查 Point MosPos = MouseInfo.getPointerInfo(
我需要使用 mouseReleased 方法而不是 mouseClicked,所以我需要找到一种方法来拦截双击。这是代码: public void mouseReleased(MouseEvent e
我试图用 java 构建一个基本程序,它创建一个带有 JPanel 的窗口,当用户点击 JPanel 时会显示图像,但是当运行应用程序并点击 JPanel 时,没有任何显示... 这里是代码... /
这个问题可能掩盖了潜在的 Swing 知识的缺乏,但我似乎无法确定我做错了什么。本质上,我想检测一个组件中的 mousePressed,然后在释放鼠标时接收鼠标下方的任何组件的 mouseReleas
我有一个按下然后松开的按钮。按下按钮时,可能会发生错误并显示 JDialog。关闭 JDialog 后,永远不会调用 mouseReleased(...) 方法。有办法解决这个问题吗? 如何用示例重现
搜索JAVA api文档,我知道了mousePressed和mouseClicked之间的区别。但是.. mouseClicked方法涉及按下和释放,因此操作是在释放鼠标后完成的,我没有发现与mous
我在一个组件上有一个 MouseListener,我想监听 mouseReleased 事件,而不需要 mousePressed 事件。我如何检测用户是否按下了另一个按钮、桌面或其他窗口(或其他任何东
我正在尝试编写一个Java程序,当您单击JFrame中的某个元素时,JLabel的背景就会改变。事件处理方法调用来更改背景的函数在从事件调用时不起作用,但是只要您在独立于任何事件的地方调用该方法,它就
我有一个 NSButton 和一个与 Button 关联的 action。我想仅在 mouseup (mouserelease) 上调用 action 方法。这可能吗?如果可以的话该怎么做? 最佳答案
如何检查用户是否在按下鼠标的同一按钮上释放了鼠标? 我想处理用户单击button1,继续按住鼠标按钮,然后拖动到button2并在button2上释放鼠标的情况,其中 button1 和 button
用鼠标选择效果很好,如下面的运行时日志所示: init: Deleting: /home/thufir/NetBeansProjects/gnumail-providers/build/built-j
我有一个网站,我希望它这样做:当我点击页面左侧的图片时,页面向后移动,当我点击右侧的图片时,页面向前移动.我已经正确设置了所有内容,所以我尝试使用 css 简单地执行此操作,onmouseover 将
我正在为 openLayers Web 应用程序(类似于 Google map )编写自动测试,尝试让它单击并拖动以平移 map ,就像任何用户通常所做的那样。经过多次尝试和研究,我仍然无法让它自动平
我将一些代码放在一起来制作这个 robot.mousePress 和 robot.mouseRelease 程序,我可以将其设置为每 500 毫秒点击一次。唯一的问题是,当我打开程序时,它工作得很好。
哪个事件先触发?它取决于初始化顺序吗?它取决于其他东西吗?这背后的原理是什么? pane.setOnMouseClicked(e -> { doSomething(); }); pane.se
我在自定义 JTable 类中选择和取消选择行时遇到问题。 我的自定义类扩展了 JTable 并实现了 MouseListener 和 MouseMotionListener。当我按下一行时,我希望该
我尝试在类 A 中处理 MousePressed 事件,该类从抽象类 B 扩展并实现接口(interface) C,但我只处理 MouseClicked,MousePressed 不起作用 接口(in
我已经通过以下方式向我的 JPanel 添加了一个鼠标监听器。输出到 JPanel 的是从一组图像绘制到屏幕上的图像。 public class NewFrame extend JFrame {
我是一名优秀的程序员,十分优秀!