0 Replies Latest reply: Jul 11, 2012 3:08 AM by 936712 RSS

    SwingWorker in Applet

    936712
      Hi,

      I have a question on using class SwingWorker and Applets.
      My usecase is this:
      I have an applet with a menue (java.awt.Choice). My applet implements ItemListener and so I can register
      the applet as itemlistener for the menue.
      I have an inner class in the applet which extends SwingWorker. This worker is constantly running in the background - when the user
      makes a choice in the menu, the worker is notified and some logic is carried out.
      I need the worker to be constantly running in the background. So, in method done() - the last thing I do is to re-instantiate the worker itself.
      Is this ok? Code below:
      public class myapplet ....{
            private MyWorker worker;
      
            init(){
                 worker = new MyWorker();
            }
      
           class MyWorker extends SwingWorker....{
      
                protected String doInBackground(){
                    while(true){
                       if(userMadeChoiceInTheMenu()){
                            return "someValue";              
                       }
                    }
                    
                }
                public void done(){
                     try{
                         showNewPageBasedOnUsersChoiceInTheMenue();
                     }
                     finally{
                          worker = new MyWorker();
                         worker.execute();
                     }
                }
          }
      }
      best regards, Håkan

      Edited by: 933709 on Jul 11, 2012 1:06 AM

      Edited by: 933709 on Jul 11, 2012 1:07 AM