java - Stoping Timer from another class -


basically code gets called jbutton(in class) move cube repainting on , on again. wish create jbutton stop timer (timer.stop()) method. how that

private actionlistener actionlistener ; public void movecube() {     actionlistener  = new actionlistener() {     public void actionperformed(actionevent actionevent) {             cube.movebox(7,5);     repaint();         }     };     timer timer = new timer( 100, actionlistener );     timer.start(); } 

you have make timer object available outside of movecube() method.

in other words: in code, define timer mytimer; @ top, , assign in movecube() method: mytimer = new timer( 100, actionlistener );. then, can call timer other button.


Comments