• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with event dispatching  RSS feed

 
sanjay krishnan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Animating image in a frame when user press keys(Left and rightarrow key) .image is moving
from left or right based on keypress and prev or next image will be shown .Here is the source code

component.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent event){
if(event.getkeyCode()==KeyEvent.VK_RIGHT)
startanimateright();
else if(event.getkeyCode()==KeyEvent.VK_LEFT)
startanimateleft();
}
};

the problem is that when i press leftkey the operation is carried out and prev image is seen.
during the operation when user presses left key again the problem starts(ie the operation
carried out incorrectly).how to avoid this?
i want the event to be happen in sequence.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're trying to prevent the starting of another startanimateleft()
until the current one completes?

if so, set a flag e.g.

boolean isRunning = false;
then in startanimateleft()

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!