Solved

How to pass variable value?

Posted on 1998-06-29
2
186 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
ID: 1224081
Edited text of question
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 20 total points
ID: 1224082
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 96
simple java question 3 55
iterator/ListIterator approach 17 25
login form jsp example 2 24
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 …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

775 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