java - Cancel anonymous SwingWorker -


i have run weird dependency when trying cancel anonymous swingworker. current code:

private static void init() {     if (connected) {         return;     }     //final swingworker<void, void> initworker;     final timer noconnectiontimer = new timer(5000, new actionlistener() {         @override         public void actionperformed(actionevent e) {             //initworker.cancel(true);             waitobject.settimedout(true);             connected = false;             waitobject.process();         }     });     new swingworker<void, void>() {         @override         public void doinbackground() {             noconnectiontimer.setrepeats(false);             noconnectiontimer.start();             cachedinstance = new network(config.host_name, config.host_port);             if (connected) {                 noconnectiontimer.stop();                 new thread(cachedinstance).start();                 waitobject.settimedout(false);                 waitobject.process();             }             return null;         }     }.execute();         } 

first assumption want verified:

i can kill new network(config.host_name, config.host_port) code killing (cancelling) swingworker.

so assuming assumption correct, want cancel anonymous swingworker, when try give name initworker, needs final such timer can reference it. swingworker needs reference timer aswell, timer needs final.

so think managed create dependancy between 2 final variables need eachother, how can fix this?

regards.

you don't have add actionlistener upon creation. pass null timer's constructor , add actionlistener afterwards, using addactionlistener.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -