java图像图标带到前面
我有一张牌的列表,它们有一个图像图标,我把所有的牌都画在牌组上,我可以用鼠标按下和鼠标标记来移动它们,现在我想在我点击一张牌时将它移到前面,当我点击它时,一张在其他牌后面的牌移到所有牌的前面。我该怎么做 这是我的鼠标压缩代码:java图像图标带到前面,java,imageicon,Java,Imageicon,我有一张牌的列表,它们有一个图像图标,我把所有的牌都画在牌组上,我可以用鼠标按下和鼠标标记来移动它们,现在我想在我点击一张牌时将它移到前面,当我点击它时,一张在其他牌后面的牌移到所有牌的前面。我该怎么做 这是我的鼠标压缩代码: 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
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
并从列表中删除所选卡,然后将其添加回顶部。然后按照列表的顺序绘制卡片。重新排列阵列顺序,以便将所选卡片移动到顶部索引。否则,考虑提供一个演示你的问题的方法。这将导致更少的混乱和更好的响应。我使用thks(inti=0;i<\u deck.size();i++){Card\u deck 1=\u deck.get(i);if(\u currentCard==u deck 1){System.out.println(“是的”);\u deck.remove(\u deck 1)deck.add(deck 1);break;}不客气。请务必将我的解决方案标记为最终答案并投票表决。