Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2006

Tip: Looking for answers? Try searching our database.

How do I pass a Text field value from one jFrame1 to jFrame2

Thread view: 
dewan.islam@gmail.com - 28 Nov 2006 10:36 GMT
I have been trying to solve this for the past 4 hours, so any pointers
would be helpful.

Problem: I have jTextField1 in jFrame1. When I call jFrame2 from
jFrame1 using "new jFrame2().setVisible(true);" command, I need to
retain the String value of jFrame1.jTextField1 in jFrame 2.

I tried creating a class called 'Global', and a public String variable
'a' within it.
1. I set Global.a = jTextField1.getText() from within jFrame1
2. jFrame2 is able to read and print the value of Global.a properly.
But, when I try this function, it it's getting caught in the if
statement - if (Global.a == "abc") {... }

What are my options for passing jFrame1.jTextField1 value to jFrame2,
so I can display that in the new form.

Thanks in advance!
Jeff - 28 Nov 2006 11:25 GMT
> I have been trying to solve this for the past 4 hours, so any pointers
> would be helpful.
[quoted text clipped - 14 lines]
>
> Thanks in advance!

In the class def for jFrame2, declare your variable and create a
function:

private String theString;

public void getMyString(String mystring) {
    theString = mystring;
}

In the method where you declare jFrame2 to be visible, one line before
that use
    jFrame2.getMyString(jTextField1.getText());

hth
/js


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.