如何检测鼠标左键按下时的移动?

发布于 2024-10-08 06:29:23 字数 111 浏览 0 评论 0原文

我想在按下左键时检测鼠标移动。

我只是创建一个绘图应用程序。我可以在不按下任何鼠标的情况下检测鼠标移动。但我想用鼠标左键检测它。

我认为没有人愿意听这个。那么,这样做的想法是什么?

I would like to detect mouse movement while the left button is pressed.

I'm simply creating a drawing application. I can detect mouse movement without any mouse being pressed. But I want to detect it WITH left mouse pressed.

I don't think there's a listener for this. So, what is the idea to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

何必那么矫情 2024-10-15 06:29:23
component.addmouseMotionListener(new MouseAdapter() {
    public void mouseDragged(MouseEvent evt) {
       if ( SwingUtilities.isLeftMouseButton(evt)) {
         // do your stuff here
       }
    }
});
component.addmouseMotionListener(new MouseAdapter() {
    public void mouseDragged(MouseEvent evt) {
       if ( SwingUtilities.isLeftMouseButton(evt)) {
         // do your stuff here
       }
    }
});
俯瞰星空 2024-10-15 06:29:23

MouseMotionListener 中有 mouseDragged 方法...检查这个更多细节...

there is mouseDragged method in MouseMotionListener...check this out for more details...

情深缘浅 2024-10-15 06:29:23

在 MouseMotionListener 中,您可以使用以下命令检查这一点:

SwingUtilities.isLeftMouseButton(me.getPoint())

并且您将侦听 mouseDragged 事件。

In your MouseMotionListener you can check for this using:

SwingUtilities.isLeftMouseButton(me.getPoint())

and you would listen for the mouseDragged event.

隱形的亼 2024-10-15 06:29:23

我认为可能有某种鼠标拖动侦听器,但如果没有......

捕获鼠标按钮按下和向上事件。在这些事件中,设置一个布尔值,例如 leftButtonIsDown = true (除非已经有一些简单的方法来查询它),然后在鼠标移动事件中使用像 if (leftButtonIsDown) 这样的块代码>

I think there might be some sort of mouse drag listener, but if not...

Capture the mouse button down and up events. In those events, set a boolean such as leftButtonIsDown = true (unless there's already some easy way to query that) and then in the mouse movement events use a block like if (leftButtonIsDown)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文