![]() |
Sponsored Link •
|
Advertisement
|
Advertisement
|
This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.
Message:
It sounds like your two (or more) classes should all implement a common interface. That interface should include getName() and setName() methods. I'm not exactly sure what you mean by connecting. That is, my guess is that you want something more than just printing out a message when two objects are "connected" because, as you progress you may want them to communicate, then disconnect and so on, right? If so, when they connect, maybe they would exchange references. Here's quick thing you might try. Have a "switchboard" Map which contains all the objects created as keys. The value of a given key would be the objects which it is connected to. Of course, it will end up being redundant (but redundancy is valued in the telephony business, right?). When a setName() is called on an Object, you look through all the keys in the map for a matching name and set its value to the setter. This means you might have a Connection or Connector class, which is notified by the setName(), so it can go make the connection. These are just my unvarnished thoughts and could probably use much more honing... - mfg > Ok this is my present situation, it a little long but please give it a read : > Ok bascially i am doing a project. My project is actually to make a GUI to simulate a Celluar Network System( Tough huh!) > Then there are other similar classes that allow the user to make the transmitting tower and also give it a name.It should be noted that a gif picture is used for the pictures of the components. > Now here is the problem. Lets jus comsider the Phone and Tranmitting tower for the time being. My project is like this. If 2 compoents eg the Phone and the Transmitting Tower have the same name they are assumed Conneted.hence if they have the same name i want my program to print "They are connected" > If they have diffrent names i want the program to print " They are not connected" > So i am assuming i need a seperate class to compare the actual names of the components the user types into the text field after double clicking the pictures of the compoenets. > How does one do this. Its harder than it sounds. Thanks for your time.
Replies: |
Sponsored Links
|