• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Updating JLabels, behavior seems odd

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.
Ranch Hand
Posts: 411
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...
A teeny tiny vulgar attempt to get you to buy our stuff
create, convert, edit or print DOC and DOCX in Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!