Passing variable between JFrame

Hi there,I have designed one JFrame to browse and searching for customerAnd another one JFrame is to display customer's detail which is selectedfrom first one.How can I pass a variable or value which is selected from JFrame1 to JFrame2?Thanks for
[297 byte] By [BomberMana] at [2007-10-3 3:48:02]
# 1
you could pass it through the costructor of JFrame2
r035198xa at 2007-7-14 21:45:02 > top of Java-index,Java Essentials,New To Java...
# 2

hi,

you could do something like this:

public static void main(String[] args){

...

ToBeShared shared = ...

YourJFrame1 jframe1 = new YourJFrame(..., shared);

YourJFrame2 jframe2 = new YourJFrame(..., shared);

Doing so, both 1 && 2 will be able to access to 'shared' variable. Beware that doing so you could introduce some concurrent programming problems that could lead to errors due to an incorrect synchronization of accesses to 'shared' variable.?br>

JoYiCk

JoYsTiCka at 2007-7-14 21:45:02 > top of Java-index,Java Essentials,New To Java...
# 3

Thanks for replies.

How can I pass it through a costructor?

String a="X";

JFrame jframe1=new JFrame(a);

jframe1.setVisible(true);

I got error warning "can not find symbol"

How to solve this?

I also have try as JoYiCk post

there is an error that "Can not find symbol; class shared"

Can you help me a little more?

Thanks a lot

BomberMana at 2007-7-14 21:45:02 > top of Java-index,Java Essentials,New To Java...
# 4

You write your own class that extends JFrame.

class MyFrame extends JFrame {

MyFrame otherFrame;

MyFrame() {

//default constructor

}

MyFrame(MyFrame mf) {

otherFrame = mf;

}

public void someMethod() {

String s = otherFrame.getWhatINeed();

}

public String getWhatINeed() {

return whatYouNeed;

}

}

floundera at 2007-7-14 21:45:02 > top of Java-index,Java Essentials,New To Java...
# 5
Hi,'ToBeShared' and 'shared' were only an example! I thought it could be clearer to use such names but they resulted confusing! You can substitute them with any class or type you want, such int, String, JTextArea etc...JoYiCk
JoYsTiCka at 2007-7-14 21:45:02 > top of Java-index,Java Essentials,New To Java...
# 6
Thanks for all help its usefull ^ ^
BomberMana at 2007-7-14 21:45:02 > top of Java-index,Java Essentials,New To Java...