• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating JLabels, behavior seems odd

 
Adam Nadeau
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got this little program I wrote as a homework assignment, and I thought I'd take some functional liberties with it. The purpose is to take four test scores and four decimals and return the weighted average. I figured I'd add a little flair with an error message if the weights didn't add to 1, and just decided to do it by swapping out JLabels. What's odd is that each result (the average or the error) will work properly once, but it will never update again. Could somebody give me some insight into why each swap would only work once? Here's the entire code (it's all in one file on purpose; assignment requirements):

EDIT: Nevermind, I just realized what I did. I originally wrote the program with everything in the window JPanel, but then added the resultPanel to the gui frame afterwards, and didn't realize I was only repainting the window.


Thanks for looking.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use one label and reset the text on the event...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!