You will have to make the Timer
object available outside of the moveCube()
method.
In other words: in your code, define Timer myTimer;
at the top, and assign it in the moveCube()
method: myTimer = new Timer( 100, actionListener );
. Then, you can call the timer from your other button.