Solved

How to pass variable value?

Posted on 1998-06-29
2
184 Views
Last Modified: 2010-04-16
If I have two classes, I set a value to a string variable in one class, eg class A. How can I pass my string variable value to a method in another class, eg. class B.

I don't want to change the constructors.

Also, how can I call a method of another class (B) to do things on that class (B) from another class (A). Eg. I want to insert some text that generated by selecting options from a dialog(class B) to a textarea (class A).
0
Comment
Question by:hcyu
2 Comments
 

Author Comment

by:hcyu
Comment Utility
Edited text of question
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 20 total points
Comment Utility
If the class B has a property theString, you can set it up either in the constructor (which you do not want to do) or you can create a methods setTheString(String value) and call it to set that property.

As for the second part, make class A a listener of events happenning in the dialog B. Or if the dialog B is modal you can show it to the user in the main thread (as soon as the dialog appears on the screen the main thread stops until the dialog disappears) and right after that get all the neceesary information from dialog B and apply it to A.

E.g,,

public class A
{
   ...
   B myDialog = new B();
   myDialog.setVisible()
   // The processing stops until B is made invisible (probably in B itself)
   // Now that the B is closed
   String text = myDialog.getText();
   this.textArea.append(text);
   ...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now