Home arrow static arrow Java Programming [Archive] - passing variables between classes during runtime
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - passing variables between classes during runtime
This topic has 1 reply on 1 page.

Posts:15
Registered: 6/28/03
passing variables between classes during runtime  
Jun 29, 2004 6:09 PM



 
I am building a gui, and there is a variable that I want to pass from one class to another. Say, I have a class A that makes a applet. A click on a button in the applet of A should result in setting a variable residing in another class B. The two classes are running simultaneously,,, and I dont know what to do in this situation.

class A
{
....

String sent ="OK";

public void ini()
{
...
s1 = new button(sent);
cp.add (s1, constraints);

s1.addActionlistener(this);
}
public void Actionperformed (actionevent e)
{
if (e.getSource() == s1)
{
## Set variable Y in Class B = sent <=== dont know.... :(
}
}
}

And, Class B looks like...

class B
{
String Y;

Y = ???
call some method in another Class C
}

I am not too good at JAVA as you can see.... I'm thinking of using a shared variable, or message passing (MPI), but those seems too much for this relatively simply-looking problem...

Thank you in advance.

sincerely,
Yosep

 

Posts:8,813
Registered: 10/4/00
Re: passing variables between classes during runtime  
Jun 29, 2004 8:09 PM (reply 1 of 1)



 
This is too general a question. There are so many ways to do this that it's hard to explain all of it on the forum. You can use listeners, accessors, public variables, inner classes, packages, and on and on. You mght try to explain what it is you are trying to accomplish.
 
This topic has 1 reply on 1 page.