Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BoxLayout can't be shared exception?

 
Albert Tarcy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm learning Java from Head First and I'm trying to write a simple GUI program that first asks if the user wants to load a game or start completely over. After that, the user gets to change the values of his character. If the user selected Restore, the TextFields contain the information that he saved last time the game was played.
However, in the method gameGui(), the JVM throws an exception at me saying that Boxlayout can't be shared. I do not understand that at all. Maybe somebody can help =)
The code(Don't worry, the bulk of it is just Swing ;)


Maybe something goes wrong in the panel.removeAll()?
I would be grateful if somebody could help. If you want to see the relatively simple GameCharacter class, here it is:

Thanks in advance for helping =)
 
Greg Brannon
Bartender
Posts: 563
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the exact error message, copied and pasted.

I'm guessing the problem is in line 73. Did you mean,

fieldPanel.setLayout(new BoxLayout(fieldPanel, BoxLayout.Y_AXIS));

instead of

fieldPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));

?

I can't check to make sure that solves the problem and that it's the only problem, so let us know.
 
Albert Tarcy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Brannon wrote:Please post the exact error message, copied and pasted.

I'm guessing the problem is in line 73. Did you mean,

fieldPanel.setLayout(new BoxLayout(fieldPanel, BoxLayout.Y_AXIS));

instead of

fieldPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));

?

I can't check to make sure that solves the problem and that it's the only problem, so let us know.


Oh, haha, what a silly mistake by me! Sorry for not posting the error message.
It works perfectly now, thanks a million!

On a side note, do you think that the program was well written? It's my first attempt at making a GUI with some function, so I'd love to hear some feedback =)
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad I could help.

I won't be able to give your code thorough consideration until later today, but I'm sure others will critque its "fitness." Please accept all comments as constructive criticism. This can be a critical group (but mostly friendly) when given the opportunity to critique code.

Edit: Empty catches aren't popular.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic