Below is a fragment of code I'm using (simplified for this post).
I'm having a problem wherein it appears that my ActionListener runs again before the last one had completed. There are two possibilies that I can think of to explain what I am seeing by placing some debug variables in the code that runs when a doClick is called on a button.
(I set a debug variable true at the beginning, and false at the end of the action for a doClick but this timer code sometimes sees the value of the debug variable as true - which it wouldn't unless....)
Either,
- A repeating 50ms timer can invoke the code in my ActionListener a second time before the first one has finished (e.g. reached the final close bracket).
- The call to doClick from my ActionListener code somehow is running asynchronously and is still active after the doClick call, such that the next time the timer goes off, the button clicking code is still running.
Can anyone explain what I am seeing?
Is there an easy way to keep the ActionListener code from running again before the previous one has finished - if this is what is happening?
[CODE=java]
ActionListener al = new ActionListener() { AT-SIGN Override // forum won't let me put an actual at sign here, says I have to many urls??? public void actionPerformed(ActionEvent arg0) { try{ // if ( debug variable is true ) then log this as a strange event // .... invoke a doClick on a Jbutton object ... }catch(IOException io){ io.printStackTrace(); } } }; // this code is executed one time only Timer tm= new Timer(1000,al); tm.setInitialDelay(1000); tm.setDelay(50); tm.start();