gpt4 book ai didi

Java swing mousemove 只触发一次

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

本质上,我想在用户从根本不移动鼠标到移动鼠标时运行一个方法。我不知道该怎么做。

自定义监听器:

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class CustomMouseListener implements MouseMotionListener, MouseListener{

//whatever other methods I have (irrelevant for the question)

public void mouseMoved(MouseEvent e){
//code goes here
//but right now it fires every time the mouse is moved, which
//is way too much, I only need one per move
}

}

最佳答案

普通算法

0. Fire mouse listener for every second with (x=x1, y=y1)

1. Store (x,y) of mouse pointer;
2. If (x,y) == (x1,y1) for another 15(or whatever you consider as time interval) sec
3. make account of (x1,y1);
4. Else do nothing;
5. If(x1,y1) changed after 15 sec
6. call mouseMove();

关于Java swing mousemove 只触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20316466/

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