I have a problem. I'm writing a character creation program and I want to use a single object to represent the character. So far, so good. The problem I'm having is passing that object to and from different JDialogs. I have different JDialogs to print, save, load, select options, etc. Here is part of the CharacterRecord object:
I use the synchronized keyword with all the methods, and the volatile keyword with all the variables.
My problem is that when I call CharacterRecord ch = CharacterRecord.getCharacter(); in my JDialogs, they do not return the curent character, they always return a blank character (i.e. an un populated character record).
It's driving me crazy!!! I know it's something simple and stupid that I missed. Please help!
If you need any additional information, please let me know.
Thanks for your help!
Joined: Dec 30, 2009
it returns empty character because you are calling static variable ch which is new CharecterRecord()
could you post more of your code? because I can see only this. I cannot see where you set the character record.
Then I don't understand why your method is synchronized - it doesn't access instance variables but static variable, but maybe I'm missing something.
Joined: Sep 09, 2009
Let me expand on my original question. Here is part of the class that displays the UI, handles user input, etc. I have methods that use the ch object, populate it based on user input, etc. On the main UI, the summary panel populates from the ch object correctly. Any use of the ch object within in the Character_FolioView class works, but any use outside of that class, like in any JDialog, seems to use a new or blank ch object.
At the beginning of the classes, I start with code like this: