我正在尝试创建一个从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");
}
}
答案 0 :(得分:1)
您可以尝试更换循环:
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++;
}