How to perform different operations within Observer's update() in Java?

Posted by Nazgulled on Stack Overflow See other posts from Stack Overflow or by Nazgulled
Published on 2010-06-01T02:05:02Z Indexed on 2010/06/01 2:13 UTC
Read the original article Hit count: 301

Filed under:
|
|
|

I just started playing with Observable, Observer and it's update() method and I can't understand what should I do when different actions call notifyObservers().

I mean, my Observable class has a few different methods that call setChanged() and notifyObservers() in the end. Depending on the called method, some part of the UI (Swing) needs to be updated. However, there is only one update() method implemented in the Observer class.

I though of passing something to the notifyObservers() method and then I can check the argument on update() but it doesn't seem feel like a good way to do it. Even if it did, what should I pass? A string with a short description of the action/method? And int, like an action/method code? Something else?

What's the best way to handle this situation?

© Stack Overflow or respective owner

Related posts about java

Related posts about update