1

我正在使用 Jframes 和 jpanels 创建一个模拟器。我已使用此代码片段来计算应用程序窗口上的点位置:

Screen screen = controller.locatedScreens().get(0);

    int handsCount = frame.hands().count();
    if(handsCount == 1)
    {
        Hand hand = frame.hands().get(0);
        int fingerCount = hand.fingers().count();
        Point2D.Float normPt = calcScreenNorm(hand, screen);
        if (fingerCount == 1)   // one finger == move point
            doodle.movePoint(normPt);
    }

}

private Point2D.Float calcScreenNorm(Hand hand, Screen screen)


  /* The dot position is calculated using the screen position that the
     user's hand is pointing at, which is then normalized to an (x,y)
     value between -1 and 1, where (0,0) is the center of the screen.
  */

  {
    Vector palm = hand.palmPosition();
    Vector direction = hand.direction();
    Vector intersect = screen.intersect(palm, direction, true);
          // intersection is in screen coordinates

    // test for NaN (not-a-number) result of intersection
    if (Float.isNaN(intersect.getX()) || Float.isNaN(intersect.getY()))
      return null;

    float xNorm = (Math.min(1, Math.max(0, intersect.getX())) - 0.5f)*2;      // constrain to -1 -- 1
    float yNorm = (Math.min(1, Math.max(0, (1-intersect.getY()))) - 0.5f)*2; 

    return new Point2D.Float(xNorm, yNorm);
  }  // end of calcScreenNorm()
I have got the point (orange dot) on the application window and i have created a jbutton (black) on the panel too.

现在,当我移动手指时(因此该点在窗口上移动),该点位于按钮下方。因此,我无法在按钮上应用我的屏幕点击手势。

请在这方面帮助我。谢谢!

4

0 回答 0