• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

JButtons, Key Press, and Obervers, et al

 
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).]
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic