I\'m making a program that is trying to animate a card moving across the screen as if you actually drew it from a desk. Here is the code for the animating:
p
The problem is you call Thread.sleep() in the Event Dispatch Thread causing the GUI become unresponsive. To avoid this you may want to use Swing Timer instead:
Timer timer = new Timer(50, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!stop) {
gamePanel.repaint();
} else {
((Timer)e.getSource()).stop();
}
}
});
timer.setRepeats(true);
timer.setDelay(50);
timer.start();
Where stop is a boolean flag that indicates the animation must stop.