Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI smiley face not functioning correctly  RSS feed

 
George Avilez
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The wink and frown button work, but when I press the smile button the face keeps the smile and the frown. ANy idea why?

 
Sam Gooding
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Avilez wrote:The wink and frown button work, but when I press the smile button the face keeps the smile and the frown. ANy idea why?



It's your logic. You turn smile and frown to true when the button is pushed but never change them to false when the other button is pushed. Then you paint them both every time. So the frown, once true is always true and the smile, once true, is always true and then you paint them one after the other. I haven't run the program, I just eyeballed it. See if that's not the problem. If it isn't , come back and I'll look more closely.

HTH
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, don't perform custom painting by overriding paint(...) in a top level window like JFrame. Instead, override paintComponent(...) in an extended JComponent or JPanel and either add that to the window or set it as the contentPane.

http://docs.oracle.com/javase/tutorial/uiswing/painting/index.html
 
George Avilez
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's your logic. You turn smile and frown to true when the button is pushed but never change them to false when the other button is pushed. Then you paint them both every time. So the frown, once true is always true and the smile, once true, is always true and then you paint them one after the other. I haven't run the program, I just eyeballed it. See if that's not the problem. If it isn't , come back and I'll look more closely.


Thanks bro, worked like a charm!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!