It is currently 27 Apr 2024, 11:25
   
Text Size

Picutre downloader

Post MTG Forge Related Programming Questions Here

Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins

Picutre downloader

Postby Snacko » 16 Jan 2010, 09:18

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.
Snacko
DEVELOPER
 
Posts: 826
Joined: 29 May 2008, 19:35
Has thanked: 4 times
Been thanked: 74 times

Return to Developer's Corner

Who is online

Users browsing this forum: No registered users and 123 guests


Who is online

In total there are 123 users online :: 0 registered, 0 hidden and 123 guests (based on users active over the past 10 minutes)
Most users ever online was 4143 on 23 Jan 2024, 08:21

Users browsing this forum: No registered users and 123 guests

Login Form