Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Help to make the method moveCardToNewPosition works, so it'possible to move card by clicking on the cards and then click in the panel and the
Help to make the method moveCardToNewPosition works, so it'possible to move card by clicking on the cards and then click in the panel and the card moves to that place. Thanks!
class DrawingPanel extends JPanel implements MouseListener, MouseMotionListener
private final ArrayList deck;
private final ArrayList throwawayPile;
private Card selectedCard;
private Point lastMousePosition;
private final CardPile newPile;
private Card card;
private int x;
private int y;
private int width;
private int height;
public DrawingPanel
deck new ArrayList;
throwawayPile new ArrayList;
addMouseListenerthis;
addMouseMotionListenerthis;
clear;
int width ;
int height ;
CardPileMiddle centerPile new CardPileMiddle Color.YELLOW
@Override
public void mouseDraggedMouseEvent e
@Override
public void mouseReleasedMouseEvent e
;
newPile new CardPile Color.GRAY
@Override
public boolean dropCardIfContainsPoint mousePoint, Card card
return false;
@Override
public void placeCardCard card
;
this.addcenterPile;
private void initializeDeck
deck.clear;
String suits HjRuKlSp;
String ranks EssKnQK;
int xOffset ;
int yOffset ;
int cardWidth ;
int cardHeight ;
for String suit : suits
for String rank : ranks
deck.addnew CardxOffset yOffset, cardWidth, cardHeight, Color.BLACK, rank, suit;
shuffleDeck;
@Override
protected void paintComponentGraphics g
super.paintComponentg;
for Card card : deck
if card.equalsselectedCard
card.drawg;
for Card card : deck
card.drawg;
if selectedCard null
selectedCard.drawg;
for Card card : throwawayPile
if card.equalsselectedCard
card.drawg;
if selectedCard null
selectedCard.drawg;
newPile.drawg;
public void moveCardToNewPositionCard card, int x int y
this.card card;
this.x x;
this.y y;
if card null
card.movex y;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started