2

同じ JPanel に JButton と Point (リープ モーションによって制御されるモーション) があります。ただし、それらは上の JButton と重なっています。

JPanel アプリケーション ウィンドウでポイントを常に一番上に表示する方法はありますか?

コード スニペットを次に示します。

public leapPanel()
{

    setLayout(null);        //18-12-13
    setBackground(Color.WHITE);
    setVisible(true);       //18-12-13
    button = new JButton();
    button.setBounds(100, 150, 100, 100);
    button.setBackground(Color.BLACK);
    add(button);

    points[nPoints] = new Point(PWIDTH/2, PHEIGHT/2);
    nPoints++;

    listener = new leapListener(this);
    controller = new Controller();
    controller.addListener(listener);       
}   

public Dimension getPreferredSize()
{   
    return new Dimension(PWIDTH, PHEIGHT); 
}

public void paintComponent(Graphics shape)
{
    super.paintComponent(shape);
    Graphics2D shaped = (Graphics2D)shape;
    shaped.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    for(int i=0; i<nPoints; i++)
    {
        shaped.setColor(Color.ORANGE);
        shaped.fillOval(points[i].x, points[i].y, 12, 12);
    }
}

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()
4

2 に答える 2

0
 JPanel main = new JPanel();
    main.setLayout(new OverlayLayout(main));
    //main.setBackground(Color.WHITE);
    setSize(800, 600);  //18-12-13
    Container con = getContentPane();
    con.setBackground(Color.WHITE);  


    BPanel = new buttonPanel();
    panel = new leapPanel();
    main.add(BPanel);
    main.add(panel);    
    con.add(main);

これにより、アプリケーション ウィンドウに BPanel のみを表示することができます。私が必要とするのは、ポイント(パネル)とボタン(BPanel)の両方をアプリケーションウィンドウに表示し、ポイントを常に上に置くことです。

ここで何か不足している場合は修正してください。ありがとう!

于 2013-12-20T02:35:41.643 に答える