Hi, guys. I am all new to java. Wondered if someone could help me please.

Basically what I am trying to achieve is:
when the button is pressed then content of textfield1 in class1 is copied to textfield2 in class2.
I would know how to do this in vb but totally blanked at java :/
Thanks for all answers :D

Recommended Answers

All 4 Replies

Do you mean something like putting a getTextFromTextField1() method in class1, which class2 would call? That's probably what I would do.

Do you mean something like putting a getTextFromTextField1() method in class1, which class2 would call? That's probably what I would do.

Yes something like that. But not sure what code i should write within the getTextFromTextField1() method?

Well, a textfield will return its contents as a String, if you ask it nicely. Why not just make your getTextFromTextField1() a wrapper for that?

To add to what jon.kiparsky said, you will then need to create an instance of the class that contains the method you require:

FirstClass first = new FirstClass();

inside the class you want to use it in, then call that method using the Class.getTextFromTextField1() syntax, where Class is the name of the class containing that method.

first.getTextFromTextField1();
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.