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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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

Processing
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
66 views