You're using netbeans? It doesn't matter what you're using though, Java works the same regardless. If you're in one class, and you make an instance of that class, a different class will not know it exists. In order for this to happen, you would have to have something like the following:
public class whatever{
whatever oneThing= new whatever();
}
public class anything{
whatever wv = null;
public anything(whatever stuff){
wv = stuff;
}
}
I hope you see what I'm trying to get at here.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
The only way to use that instance is to have a variable of that class's type in the other class. So if you have two classes, class one and class two, and you want to use class one from inside class two, class two has to have a variable of type class one.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
public class First{
First thing = new First();
public static void main(String[] args){
Second second = new Second(thing);
}
}
public class Second{
First whatever = null;
public Second(First param){
whatever = param;
}
}
You basically just pass one Object of the first class's type as a parameter to a method in the other class.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
If you have an object, you can use methods in that Object's class. So if you used the setup I had above, you could access any instance variables of "whatever" from the Second class.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
It seems like you've done what I suggested. Assuming Class 1 is named Client, and Class 1 has a method called sendData, then you should be fine. But if you want Class 3 to communicate with Class 1 (or Class 2) you will have to share the objects among those classes as well.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
You can share Objects among classes through a constructor (or other method) of one class that accepts a parameter of the other class. See the example I already posted.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
I'm not going to write the code for you. You already did what I'm talking about once, with the theClient instance. Just do it again.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Hey, I am not telling you to write the code for me. WTF, I am just asking for help. Its not working thats why I asking you to write your example in the same context. Anyway, don't reply to this thread if you don't want to help.
You are just explaining with complicated words, I've already told you that I am new to Java.
If you don't know something, don't try to act smart, OK !! I am losing my time trying your stupid complicated examples.
You are just a dumb and thanks a lot for your complicated help ... hope someone else will help me and learn to be polite.
It sounded to me like you were asking me to write the code for you. If this wasn't the case, there is no need for you to get upset about it, just clarify what you meant. And obviously, I wanted to help because I responded to this thread. I already know how to do the task you're attempting, and have done the same thing in the past, so it isn't a question of me "not knowing it". And your personal attacks on me are very offensive and uncalled for.
Also, if you don't know what terms such as "parameter" etc mean, you could have asked for clarification or looked them up. If you aren't willing to put in effort to learn, then don't expect your code to work. And if you don't understand the simple terms I used, that is fine, but like I said - try to learn them - don't place blame on me for trying to help you.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Any help offered here is a completely voluntary effort. As such, your own attitude is going to determine the extent and nature of that help. The attitude demonstrated above is certainly not going to encourage much assistance in the future.
Good luck with your efforts.
(You should also know that most posters never mark their questions as solved. Many don't even trouble themselves to say thanks or come back at all after their issue is resolved. Using that as a metric of "helpfulness" is useless.)
Ezzaral
Posting Genius
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847