Solved

How to pass variable value?

Posted on 1998-06-29
2
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 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