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 / GUI / March 2004

Tip: Looking for answers? Try searching our database.

Passing objects between two JFrames

Thread view: 
Dan Madeira - 12 Mar 2004 14:20 GMT
Hi all,

I have a slight problem at the moment... I have a main Swing program
that needs the manual input of data. I've decided that it should be
handled in a seperate JFrame which would, once the user has finished,
pass the data object back to the main program, sort of like
JFileChooser passing back a File object to the main program. However
I'm not really sure how to go about it.

Could someone please help?

Cheers,

Dan
John Davison - 12 Mar 2004 18:36 GMT
> Hi all,
>
[quoted text clipped - 10 lines]
>
> Dan

Sounds like a job for JDialog to me.  Extend it, and add your own getter
functions.

For example, let's say you have a custom JDialog called MyJDialog, and
you created an internal property called userInput of type String, which
you created a getter function for called public String getUserInput();
In that case, here's the code to go in your JFrame.

MyJDialog dialog = new MyJDialog(this, true); // make it modal (means
nothing else can have focus until this dialog is disposed)
dialog.show();
String result = dialog.getUserInput();

If you want the user to be able to still access the JFrame while the
JDialog is showing, pass in a value of false as the second parameter to
the constructor.

John Davison
Dan Madeira - 13 Mar 2004 13:56 GMT
> > Hi all,
> >
[quoted text clipped - 29 lines]
>
> John Davison

Ok, thanks a lot for the advice, but I've run into another problem...
I had to alter a couple of lines of code and now Java is giving me the
exception:

java.lang.IllegalArgumentException: adding a window to a container

when refering to the line:

frame.getContentPane().add(new ManualInput(),BorderLayout.CENTER);

which is my line for adding the entire thing to the main JDialog.

This is after it asked me to change frame.add() to
frame.getContentPane().add() which I guess is a problem with using AWT
code instead of swing, but after changing all the references it gives
me the above exception.

Could you please help me a tiny bit more?

Thanks
Andrew Thompson - 13 Mar 2004 14:12 GMT
>>> Hi all,
>>>
>>> I have a slight problem at the moment...

> Could you please help me a tiny bit more?

I'll help you to help yourself a whole _lot_ more..
<http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JDialog.html>

The API docs, starting with the ones
for the component you are trying to use..

Signature

Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology

Dan Madeira - 13 Mar 2004 15:04 GMT
> > Hi all,
> >
[quoted text clipped - 29 lines]
>
> John Davison

Actually, ignore that second message, I've managed to get working perfectly.

Thanks,

Dan


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.