2016-01-07 42 views
0

我想做一个程序,从mongoDB的数据库中找到坐标值x和y。之后,减去这些值以便每次查找它们的各种值并搜索新坐标的位置。如何获得结果作为值

结果的结构,例如:屏幕外(计数):{“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");      
       } 
      } 

回答

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++;          
     } 
+0

谢谢您的回答。是的,我做到了,以后我将如何给(x2,x1,y2,y1)(offScreen)的值。 – William

+0

如果您想设置x offScreen的值,例如x2。你可以这样做:'DBObject temp = doc1.get(“offScreen”);'然后'int x2 =(int)temp.get(“x”);' –

+0

aaaa ok非常感谢! – William