BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Excanging Values Between JFrames

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE
View previous topic :: View next topic  
Author Message
stefman
Guest





PostPosted: Wed Jun 14, 2006 9:15 pm    Post subject: Excanging Values Between JFrames Reply with quote



Hello everyone,

I'm working on a swing application and i have simple problem but
i have not found a proper solution yet.
The problem is how can i send values between Jframes, for example,
the first jframe has a jlabel and a jbutton, when the jbutton pressed the second jframe is showed which contains a jtext
and a jbutton,how can i pass the jtext text to the first jframe's jlabel for example by pressing the second's jframe's jbutton.

Any example or resource would much too helpful.
Thanks.
Back to top
Kevin Dean [TeamB]
Guest





PostPosted: Thu Jun 15, 2006 6:14 am    Post subject: Re: Excanging Values Between JFrames Reply with quote



stefman wrote:

Quote:
I'm working on a swing application and i have simple problem but
i have not found a proper solution yet.
The problem is how can i send values between Jframes, for example,
the first jframe has a jlabel and a jbutton, when the jbutton pressed the
second jframe is showed which contains a jtext
and a jbutton,how can i pass the jtext text to the first jframe's jlabel
for example by pressing the second's jframe's jbutton.


If frame #2 is created by frame #1:

MyFrame2 myFrame2 = new MyFrame2();
myFrame2->passTheValue(someTextField.getText());
myFrame2->show();

You would then display the value in MyFrame2.passTheValue().

If frame #2 is not created by frame #1, the code is almost identical
except you have to pass the pointer to frame #2 into frame #1 using
similar architecture.

--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
http://www.datadevelopment.com/

NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
http://www.datadevelopment.com/papers/index.html

Please see Borland's newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html
Back to top
Paul Furbacher [TeamB]
Guest





PostPosted: Thu Jun 15, 2006 6:41 am    Post subject: Re: Excanging Values Between JFrames Reply with quote



Kevin Dean [TeamB] wrote:
Quote:
stefman wrote:

I'm working on a swing application and i have simple problem but
i have not found a proper solution yet.
The problem is how can i send values between Jframes, for example,
the first jframe has a jlabel and a jbutton, when the jbutton pressed
the second jframe is showed which contains a jtext
and a jbutton,how can i pass the jtext text to the first jframe's
jlabel for example by pressing the second's jframe's jbutton.


If frame #2 is created by frame #1:

MyFrame2 myFrame2 = new MyFrame2();
myFrame2->passTheValue(someTextField.getText());
myFrame2->show();

You would then display the value in MyFrame2.passTheValue().

If frame #2 is not created by frame #1, the code is almost identical
except you have to pass the pointer to frame #2 into frame #1 using
similar architecture.

That's one way which is very straight forward. However,
there is an alternative. Thought exercise (a.k.a., gedanken
experiment): imagine that frame #1 is just a label on frame #2.
What do you implement in frame #2 to have frame #2 receive
the button event?

It's not so much about reading, but listening. (That's a
clue.)


--


Paul Furbacher (TeamB)

Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Back to top
stefman
Guest





PostPosted: Sat Jun 17, 2006 7:58 am    Post subject: Re: Excanging Values Between JFrames Reply with quote

Thanks both for your responses,

Finally i've found a solution but it seems different from yours
and i would like to have your a opininion about the correctness
of my solution.
I used a static variable or object and i access the variable or
object using MyPackageName.MyClassName.MyMethodName.VariableName.
For example
JFrame 1
static int x=5;
JFrame 2
PackageName.ClassName.x=7;

It is working fine, but i'm wondering about stability.
Thanks again!Steve.
Back to top
Paul Furbacher [TeamB]
Guest





PostPosted: Sat Jun 17, 2006 8:11 pm    Post subject: Re: Excanging Values Between JFrames Reply with quote

stefman wrote:
Quote:
Thanks both for your responses,

Finally i've found a solution but it seems different from yours
and i would like to have your a opininion about the correctness
of my solution.
I used a static variable or object and i access the variable or
object using MyPackageName.MyClassName.MyMethodName.VariableName.
For example
JFrame 1
static int x=5;
JFrame 2
PackageName.ClassName.x=7;

It is working fine, but i'm wondering about stability.

Stability is not the concern. Since you are using a
static variable, the value will apply to all instances
of that frame class. That's probably not what you
want, unless you know that you'll never have more
than one instance of the frame showing in this application.

Sorry if I'm being too blunt, but this is the least
attractive solution to the problem. Kevin's is easiest
to implement; the one I suggested takes more time. It's
slightly more decoupled, but that again may not be necessary
in your application's design.


--


Paul Furbacher (TeamB)

Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html

Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html

Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder IDE All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.