• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing components not updating with current values

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm writing a game that has an Advert class. At the start of the game, an ArrayList<Advert> will be deserialized from file, containing all the adverts. I'm also writing an Advert Editor to create/edit an ArrayList<Advert> and serialize it to file. The Editor looks like this :



The problem I'm having : when you push the "Previous", "Next" or "New Advert" button, everything goes fine except the values in the fields are only updated when they are related to a String (Title & Description). The fields related to an int (Bonus, Penalty, Minimum Viewers, ...) or boolean (XRated Mandatory & Forbidden) always keep their value. My guess is that I must be overlooking something in the following 2 methods that are called from the button's actionlisteners. The first one updates the text of the Swing components using the getters of the active advert in the ArrayList. The second one does just the opposite : it calls the setters of the active advert in the ArrayList with the values from the Swing components.




Anyone who could give me a hint what I might be doing wrong ?
[ October 25, 2008: Message edited by: Bert Deville ]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please show us the ActionListeners you are using for the buttons.
 
Bert Deville
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Difficult to see what's wrong; it is something very subtle.

Set up a print buttonAnd make sure the Advert class has a decent toString method. See what it prints. And try adding a print statement to print the current Advert to the next and previous buttons. That should allow you to see whether the data are actually being recorded in the Buttons.

You can always remove the print button and print statements later.

When you click the "new" button, do you get 0s in the number fields? Does the Advert 1/1 bit update correctly?

I am afraid I can't see the error. Sorry.
Anybody else got an idea, please?
 
Bert Deville
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very strange, I added all the print-stuff but now it actually works correctly. I can't remember changing anything besides adding a print-button and print-statements in refresh(), updateList() and all 3 actionlisteners for the buttons.

So thanks for your help, I still don't know what was wrong, but at least I got it working now. ;-)
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome ( ) . . . to whatever I didn't do that helped!
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic