java imageicon 置顶

java imageicon bring to front

我有一个卡片列表,它们有一个图像图标,我把所有的卡片都画在牌组上,我可以用 mousePressed 和 mouseDragged 移动它们,现在我想在单击时将卡片放在前面它是一张位于其他卡片后面的卡片,当我单击它时,它会移动到所有卡片的前面。我该怎么做?

这是我的鼠标按下代码:

int x = e.getX();   // Save the x coord of the click
int y = e.getY();   // Save the y coord of the click

//... Find card image this is in.  Check from top down.
_currentCard = null;  // Assume not in any image.
for (int crd=_deck.length-1; crd>=0; crd--) {
    Card testCard = _deck[crd];
    if (testCard.contains(x, y)) {
        //... Found, remember this card for dragging.
        _dragFromX = x - testCard.getX();  // how far from left
        _dragFromY = x - testCard.getY();  // how far from top
         _currentCard = testCard; // Remember what we're dragging.

        break;        // Stop when we find the first match.
    }
}

使用 ArrayList 并从列表中删除所选卡片并将其重新添加到顶部。然后按照列表的顺序画卡片。