Page 1 of 1

Picutre downloader

PostPosted: 16 Jan 2010, 09:18
by Snacko
As swing is single threaded you can't access it from other thread as the drawing thread. As such your update() methods throw an exception and don't update the card coutner x/23131.
It should be accessed like:
Code: Select all
    private void update(int card) {
        this.card = card;
        final class Worker implements Runnable{
         private int card;
         Worker(int card){
            this.card = card;
         }

         public void run() {
              fireStateChanged();
              bar.setString(String.format(ForgeProps.getLocalized(card == cards.length? BAR_CLOSE:BAR_WAIT), card,
                      cards.length));
              System.out.println(card + "/" + cards.length);
         }
      };
      EventQueue.invokeLater(new Worker(card));
    }
EventQueue.invokeLater makes the operation take place at drawing thread. This is the mandatory if you use multiple threads and want to update some Swing elements.