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

Observer not getting updated  RSS feed

 
Ariana Hobson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a java swing app with card layout which implements observer/observable. My problem is the observer doesn't get updated when calculated value is changed. To simplify the code, the calculate method just returns the value input in the textfield. Basically in the 1st card, I key in any number then click Calculate button. This will invoke the calculate method which just returns the keyed in number. Right now the text field in the 2nd card is blank. Thanks in advance!

Card layout:


First Card:


Second card which is the Observer:


Observable:

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1103
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several problems with the code, but to begin with, you have an incorrect understanding of CardLayout. I don't see any CardLayout methods being called - simply setting the panels visibility will not show them.
I suggest you go through Swing Tutorial for CardLayout to understand it and use.

Another suggestion would be to separate the Observer/Observable code from GUI and test it separately first before integrating with GUI.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!