Hello,
I need your help again guys. I am trying to make a pop up form name setIPInterface (when the user click on a button in the form "ClientInterface"), for a user to input an ip address in a textfield and when the user click on the button "Set", the value of the textfield will be send to a method named "setIP()" found in another class named "Client()".

The code of the button "Set":

theClient.setIPAddress(txtIPAddress.getText());

theClient is an instance of the class Client.

but I've got the following error:

java:75: cannot find symbol
symbol : variable theClient
location: class ignisv10.SetIP
theClient.setIPAddress(txtIPAddress.getText());
1 error

Note that the instance "theClient" have already been instantiated in the form "ClientInterface". The user clicks on the button which is found on the ClientInterface form then another form will pop up named "setIPInterface".

Thanks in advance for your help.

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.

Sorry, but I am a bit confused. The class has already been initialized, I want to use the instance that have already been initialized but with is found in another class.

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.

Can you give me an example please. I am stuck on this part of the program, I am currently developing a chat system and am a bit new to Java. I just want to understand the concept of communicating between classes.

Actually there are 3 classes. Class 2 already have an instance of class 1, I want class 3 to use the same instance of class 2 to be able to use a method found in class 1.

Thanks in advance.

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.

Thanks for the answer. But what should I put in the third class button.

Let said, the third class contain a button named "Set" and on click it should pass the value IP(fetch from a text field in the third class itself) to the class 1?

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.

Hello, thanks again for the answer, I've have tried it but its not working. Wait, I am sending you the class 2 and class 3.

The Class 1 contains the the Class Client() and the methods setIP and getIP. I am not sending the class 1 because its an assignment, I have worked hard on it, I don't want another student to put hand on my code. Hope you understand.

Note: The Class 2 contains the main and the interface of the client.

The Class 3 is the pop up form that i want to use in order to set the ip in class 1.

//theClient.setIPAddress(txtIPAddress.getText());

. Check this part in the class 3, its here that I want to pass the value to class 1.

Actually, I don't even know if what I am doing is possible or not in Java. I just want to make my interface easier to use.

I hope that you have understood my objective. Many thanks in advance dude.

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.

Yeah, class 1 have the method sendData(). How to share objects among classes?

Don't forget that class 2 have the instance theClient. I want to set the IP for the instance theClient for the program to work properly else it will not be able to communicate with the server.

Thanks a lot.

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.

Can you please modify your example according to my code. I am a bit confuse with the example. Thanks.

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.

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.

commented: not cool +0
commented: I think you just blew most of your chances for help here. -4

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.

"and will probably result in you not getting as much help here in the future." Are you threatening me or what?

I don't like this attitude from you, I am here to have some help and not to fight with you, OK. Please at least show a little respect.

I presume that you work for Dani Web. I do the same job for Tom's guide(in french) but on the "Troubleshooting section". I know how to talk to people on a forum and now you are threatening me. You think that you have the right to do that ?? You stood so low. One thing is sure, you don't know how to help people.


In your 490 posts you have solved only 48 thread which shows how "good" you are. Anyway, I got help from James earlier, check out his explanation, even a baby("I've told you that was new to Java" and "I've worked really hard on this program") will understand his example. Hope you will learn from him.

Note: I just wanted you to write your example in the same context as my program, that's all. I have not told to write the whole stuff for me. Btw, my code is working fine now, I've got the solution from another forum. I will continue to post my questions on Dani Web, there are other peoples over here which will surely help me.

Sincerely,
Bryan Jimmee Hugges

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.)

OK ... Anyway Thanks.

Solution: Use abstract class concept.

I'm glad you solved whatever issue you were having, and no, I do not work for Daniweb. I'm also not sure how you could interpret my attitude as arrogant or unpleasant, and I'm somewhat confused. But I'll leave this be.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.