I'm coding a program to move a player on the screen,
but the program directly show me the end,
which is my player reach the end point,
the animation part dose not display,
just like the player straight away jump to the end.

how can i modify my code to show the movement of the player?
here is my run function,


Code:
Thread t;
 
public void run() {
    while (isClick) {
        try {
            int j = playerStep + 40; 
            while(playerStep < j) {
                try {
                    playerStep += 10;
                    repaint();
                    t.sleep(300);
                } catch (InterruptedException err) {
                    JOptionPane.showMessageDialog(null, "Moving error!");
                }
            }
        } catch (InterruptedException err) {
            JOptionPane.showMessageDialog(null, "Drawing error!");
        }
        isClick = false;
        repaint();
    }
}
i use button click to start the animation

thanks a lot