0

我正在制作一个程序,用户将使用鼠标在桌子上拖动一张卡片。卡片是 a JPanel,桌子也是。表有null布局。在 Card 类中,我有这个:

@Override
public void mouseDragged(MouseEvent e) 
{
    if (this.getWhere() == 1) // makes sure the card is on the table
    {

        Table.table.moveCard(this, e.getX(), e.getY());
    }
}

然后在 Table 类中:

public void moveCard(Card card, int x, int y)
{
    card.setLocation(x, y);
}

当我拖动卡片时,它会从鼠标所在的位置和面板左上角附近的一个点来回跳跃。

有什么帮助吗?

4

0 回答 0