• Post Reply Bookmark Topic Watch Topic
  • New Topic

JButtons, Key Press, and Obervers, et al

 
BillR
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First the question, then the reason I am asking ... in case you want to know!
In the update method of the observer interface, it will tell you the source of the observerable object.
public void update(Observable source, Object state)
Can someone tell me what exactly the 'source' is telling me? For example, what do I need to do to differentiate between different sources if there is more than one observable object and the observer only wants to handle observable events from particular ones. I know a selection statement (if, switch) can be used, but I don't really understand the details of what to compare to what. I know how to use if and switch very well... I used to do 'C' ;-). For example what is it the 'source' is telling me? (the objects name/reference? it's class?) And what do I need to do to compare it against something else. For example, I only want the observer to react to some types of objects, but not others.
Thanks BillR

Rational:
As a self imposed exercise, I am trying to consolodate what I have taught myself so far by writing a calculator application. I think I have figured out how to grab key press events to trigger specific calculator keys (subclassed JButtons which have their own little messages to send when fired)... even when they are not in focus by 'listening' with a higher level container (like a JPanel) and setting up an observerable interface so that the different keys can listen and tell if they should do their thing. The keys themselves have observer classes to listen and observable interfaces to let the program 'know' that the calculator key is talking to it... or trying to. I am doing this rather than sending an explicit message to the other object specifically in order to keep the calculator keys generalized and thus re-useable without having to figure out which lines of code to change. Maybe even make it in to a generalized keypad component for re-useablity... what a concept this OOP! :-)
If you read this far thanks... hope you can help me out.

[This message has been edited by BillR (edited April 11, 2000).]
[This message has been edited by BillR (edited April 11, 2000).]
[This message has been edited by BillR (edited April 19, 2000).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!