gpt4 book ai didi

java - 无法跳出循环

转载 作者:行者123 更新时间:2023-12-01 23:05:50 25 4
gpt4 key购买 nike

这是 while 循环:

do {
PointerInfo a = MouseInfo.getPointerInfo();
Point b = a.getLocation();
int nx = (int) b.getX();
int ny = (int) b.getY();
String sendMessage1 = nx + "\n";
String sendMessage2 = ny + "\n";

MouseEvent me = null;
penOperationS(me,nxi-120,nyi-75,nx-120,ny-75);

bw.write(sendMessage1);
bw.write(sendMessage2);
bw.flush();

}while(true);

在我的代码中,当拖动鼠标时,控件进入此循环(mouseDragged(MouseEvent e))。我的问题是,即使释放鼠标,循环也会继续执行。我想在释放鼠标时退出循环。我应该为此做什么?

请帮忙..提前致谢..

最佳答案

做这样的事情,用heldDown作为成员变量:

heldDown = true;
do {
...
} while (heldDown);

然后,在鼠标释放事件中:

heldDown = false;

这应该可以解决问题。

关于java - 无法跳出循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22765071/

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