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!
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.
SCJP 1.4, OCMJEA/SCEA 5.0.
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF