Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Jumping Image Effect

807589Jul 9 2008 — edited Jul 10 2008
I have a picture of a little stick figure man and i want to make it appear as if he is jumping.
The code I have to do that is this:
		switch(e.getKeyCode()){
			case KeyEvent.VK_UP:
				for(int i=0; i<=10; i=i+1){
					y = y+1;  //the int y represents the images position of the y-axis
					repaint();
					try{Thread.sleep(200);}
						catch(InterruptedException ie){}
						
					if(i == 10){
						for(int j=0; j<=10; j=j+1){
							y = y-1;
							repaint();
							try{Thread.sleep(200);}
							catch(InterruptedException ie){}
						}
						break;
					}
				}
				break;
but for some reason the image just stays in one place and does not have the jumping effect I wanted.
(proabably has to do with the Thread.sleep(200); method I called, but I dont know how to fix it).

Thanks in advance!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 7 2008
Added on Jul 9 2008
9 comments
87 views