View Single Post
  #1 (permalink)  
Old 08-06-2007, 08:31 PM
jiuhu jiuhu is offline
Member
 
Join Date: Aug 2007
Posts: 3
jiuhu is on a distinguished road
How to use the sleep and thread?
I'm coding a program to move a player on the screen,
but the program directly run to the end,
the animation part dose not display,
how can i modify my code to show the movement of the player?

here is the run function,


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

Thanks a lot.
Reply With Quote
Sponsored Links