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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -