<小时/>
我正在尝试编写一个从 mongoDB 数据库中查找坐标值 x 和 y 的程序。之后,将这些值相减,找出每次的变化,并搜索新坐标的位置。
结果的结构例如:offscreen(count): { "x": "1248", "y": "698"}
我已经做了一些事情,但我不知道如何给出 (x2,x1,y2,y1) 的值,或者它有更好的解决方案。
感谢您的帮助..
int x_and_y = 1;
while (cursorEvents.hasNext()) {
DBObject documentInEventCollection = cursorEvents.next();
if("mouseMove".equals(documentInEventCollection.get("type"))){
System.out.println("offscreen(" + x_and_y + "): " + documentInEventCollection.get("offScreen").toString());
x_and_y++;
}
if("mouseMove".equals(documentInEventCollection.get("type"))){
if((x2 - x1) < 0 ){
System.out.println("Right");
}else {
System.out.println("Left");
}
if((y2 - y1) > 0 ){
System.out.println("Down");
}else{
System.out.println("Up");
}
}
最佳答案
您可以尝试通过以下方式替换循环 while :
while (cursorEvents.hasNext())
{
DBObject doc1 = cursorEvents.next();
if(cursorEvents.hasNext())
{
DBObject doc2 = cursorEvents.next();
}
if("mouseMove".equals(documentInEventCollection.get("type"))){
System.out.println("offscreen(" + x_and_y + "): " + doc1.get("offScreen").toString()+","+doc2.get("offScreen").toString());
x_and_y++;
}
关于java - 如何获取结果作为值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34656666/