Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to pass variable value?

Posted on 1998-06-29
2
Medium Priority
?
192 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 60 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

730 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