• Post Reply Bookmark Topic Watch Topic
  • New Topic

update() method problem in Observer interface  RSS feed

 
Raheel rancher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
This is one of the most strange problems that I'm experiencing right now. I have designed a gui based app made in swing with MVC pattern. To implement mvc practices, I have used Observer and Observable combination. Just for the ease of UI designing, I made use of jbuilder 7 and then with the passage of time I started coding its model and controller components in normal editors (like textpad). Problem is that when i invoke my application from command-line, my update() method (that i have been override for Observer interface) didn't get called !!! Yes, it happened with me and when I invoke my application from jbuilder IDE, it worked fine. I checked all the classpaths, compiled my sources from cmdline, did complete of all static resources that I am using in it; but of no use. It should be noted here that methods defined in my model class (child of Observable class) get called properly but when methods and called from model, my method didn't get call in my UI class, which is implementing Observer interface). This problem only appears when I launch my application from command line.
Plz HLEP me as I am totally stuck to it now.
Thanks.
 
Eddie Vanda
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update () should probably start with lower case u. But if that is just a typo, try to simplify your code so it still shows the problem and we can try it out for you. Often you fix the problem by yourself through the process of simplification.
 
Raheel rancher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eddie n thanks. First of all it was a typo in my post but not in my actual coding. Secondly, I solved the problem. How I solve it, i really want to share it with you and other people out there. Actually, it was due to event dispatching mechanism employed in jfc/swing components. I just put part of my code responsible for showing the jframe inside a separate class which is implementing runnable interface and then i throw the instance of that class to EventQue. Below is what I changed:

And it solved my problem. Now I can get called my [BOLD]update()[/BOLD] method from command line as well.
I hope this description will help others as well. To understand the event dispatching in a more detailed way, you & others can view a nice JDC Tech-Tip from Sun. Its link is:
Multithreading in Swing
Thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!