This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing components not updating with current values

 
Bert Deville
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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 ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome ( ) . . . to whatever I didn't do that helped!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic