The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

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:

Making a Connection

Posted by Matt Gerrans on November 28, 2001 at 2:53 PM

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 i posted a question earlier today and someone told me to be more specific about my problem ..so here i go.. i hope this is better...

> 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!)
> So bacially in a Celluar System there are many component eg. the Phone , transmitting Tower , cables and so on.
> Ok so basically i have a main screen with buttons on the side of the screen. And whenever i click a button it adds one of the compoents of the celluar system to the screen( It actually adds a small picture of the phone or transmitting tower or cable to the screen depending on which button i press.
> Hence it can be assumed the Code to make this screen with the various buttons to added the celluar compoenets to the screen is one class.
> Now there are other classes that actually make the picture of the component.Eg there is a seperate class that makes the picture of the phone and allows the user to double click on the phone and then a text field appears which allows the user to give the phone a name. When the person eneters the name of the phone example "phone1" and presses eneter the word phone one appears under the picture of the phone. Now this is class two.

> 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



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us