I'm trying to animate an object using the swing timer. I need the object to change its y coordinate each time until it reaches the bottom. With the code below, how could I paint the animated piece through it's animation, before painting all of the pieces in the list within the for loop?
int x = (getMouseX()) * 70 + 10;
int y = mover.getRow() * 70 + 10;
pieceList.add(new Oval(x, y, 50, 50, setPieceColor()));
g.setColor(setPieceColor());
// **** Animate new piece being dropped here ****
for (int i = 0; i < pieceList.size(); i++) {
g.setColor(pieceList.get(i).getColor());
g.fillOval((int) pieceList.get(i).getX(), (int) pieceList.get(i).getY(), (int) pieceList.get(i).getWidth(), (int) pieceList.get(i).getHeight());
}
mover.previewMove(g2d, getCurrentColumn());
My issue with animating the piece is that I'm unsure how to do it so that it isn't painted in it's final place before it has dropped. Since I'm adding each piece to a list as it's played, the list of pieces are all being painted after every click / mouse movement. How could I animate the dropping piece before it is added into the list to be drawn on each of the following turns?