aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Parent/Child Window Communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Parent/Child Window Communication" Watch "Parent/Child Window Communication" New topic
Author

Parent/Child Window Communication

Lang Miao
Greenhorn

Joined: Oct 22, 2004
Posts: 12
Background: I have a parent window (JFrame object) CustomerForm and a child window (JFrame object) InsertForm. InsertForm is displayed when insert button on CustomerForm is clicked.

Question:
1. When InsertForm is displayed, how can I make CustomerForm not accessible? Previously I use setFocusableWindowState( false ) but that only makes CustomerForm stays behind InsertForm; the buttons on CustomerForm are still clickable.

2. How do I pass info on InsertForm to CustomerForm? I have text fields of Name, Address, etc. Do I just use getText() and pass the values to CustomerForm's variable?

Thanks in advance
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
>1. When InsertForm is displayed, how can I make CustomerForm not accessible?

when InsertForm is created, next line = CustomerForm.setVisible(false);
in the constructor of InsertForm, have

2. How do I pass info on InsertForm to CustomerForm?
either make InsertForm an inner class (exposing the variables to InsertForm)
or pass a reference to CustomerForm when InsertForm is created


then, in the window closing event you add the code to update CustomerForm data
Lang Miao
Greenhorn

Joined: Oct 22, 2004
Posts: 12
Regarding your solution #1
The CustomerForm, then, will be hidden. I just want to deactive it. User still sees it but can't bring it on top or press any buttons on it
I come up with this one. Let me know if this sufficient.


Thanks a bunch for the previous reply. Solution #2 works great.
[ October 22, 2004: Message edited by: Lang Miao ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / AWT / SWT / JFace forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ted Reynolds
Greenhorn

Joined: Mar 16, 2004
Posts: 20
Have you thought of trying the following?
instead of extending JFrame for your insert form have it extend JDialog and then make the dialog modal when you instantiate it.
Lang Miao
Greenhorn

Joined: Oct 22, 2004
Posts: 12
I didn't know I have that option. Thanks for pointing that out. I knew that I tried to reinvent the wheel
Lang Miao
Greenhorn

Joined: Oct 22, 2004
Posts: 12
CustomerForm (parent) has customerIDJTextField, InsertDialog (child) has customerIDJTextField as well. I want it when okButton on InsertDialog pressed, text in InsertDialog.customerIDJTextField be passed to CustomerForm.customerIDJTextField. The following does not do it.


Thnx for the help

[ October 28, 2004: Message edited by: Lang Miao ]
[ October 28, 2004: Message edited by: Lang Miao ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Your code looks okay with one exception — the variable customerForm in this line

should be the member variable custForm declared above the constructor

It's your reference to the CustomerForm class which you will use to access methods and members of that class.
Lang Miao
Greenhorn

Joined: Oct 22, 2004
Posts: 12
I tried to incorporate your code. Stuck on this one

I don't know how to do it with my class organization

I instantiate CustomerForm from main(). You instantiate within the class itself. Any difference?
Is that super() that makes it work?
[ October 29, 2004: Message edited by: Lang Miao ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
CustomerForm extends JFrame which means that CustomerForm is a JFrame. In addition to all the other things that CustomerForm is, ie, the state of it's member variables and it's behavior via methods, CustomerForm is a JFrame.

In the same way, InsertDialog is a JDialog. The creation of the dialog in InsertDialog happens inside the InsertDialog constructor with the call to InsertDialog's superclass, which is JDialog since InsertDialog extends JDialog, in the line

Looking at the constructors in the Constructor Summary section of the JDialog api, this constructor has the signature

So the first argument to the constructor must be a Frame. Do we have one? At the top of the JFrame api is a class hierarchy diagram that shows JFrame extending from Frame. And just below this, under the horizontal rule, is the class declaration public class JFrame extends Frame implements .... A JFrame is a Frame, and more, of course.

We need to use the CustomerForm JFrame as the first argument in the JDialog constructor. Since CustomerForm is a JFrame we can use, or pass in, the local variable owner

The call to super must be the first statement in the constructor so we only have access to the local variable. By contrast, the class Coordination is not a JFrame but does have a JFrame member variable f. So we pass this member variable in to the constructor

in CustomDialog using the local variable c and dot notation to access the member variable f.

In the next line of the CustomDialog constructor we instantiate the member variable coordination by assigning it the value of the local variable c. After this the variable coordination has access to these member variables and method in Coordination

I instantiate CustomerForm from main(). You instantiate within the class itself. Any difference?
Lang Miao
Greenhorn

Joined: Oct 22, 2004
Posts: 12
As hard as I've tried to make it work with my program, I still couldn't resolve it. I decided to change my program design and put this off until I have more time to work on it. Just want to drop much thank to whom it's due. Peace out
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Parent/Child Window Communication