Accessing other Frames components

C

carmelo

Hi everybody,
I'm developing a Swing app with a main Frame which contains multiple
JInternalFrames.

I need to make something like this:

We have 2 JInternalFrame: intf1 and intf2.
intf1 contains some JTextFields and some JButtons.
intf2 contains a JTable.

On intf1, when button Button2 is clicked, intf2 must open. On intf2
there are some values on a JTable, which should be passed to the
calling JInternalFrame (in this case intf1) writing them on its
JTextField.

Regarding the intf2 opening on Button2 click, I was able to do that
accessing the main Frame (let's call it frmMain) in this way:

if (frmMain.intf2 == null) {
frmMain.intf2 = new JInternalFrame("Internal Frame
2",true,true,true,true);
frmMain.intf2.setContentPane(new IntFrame2());
frmMain.intf2.setBounds(12, 9, 500, 400);
frmMain.jDesktopPane1.add(frmMain. intf2);
frmMain.jDesktopPane1.updateUI();
}
frmMain.intf2.show();

What do you think about it?

Regarding the access to the calling JTextField I don't know...
How can I do? I hope you can help me


Thank you very much in advance!
 
M

markspace

carmelo said:
Hi everybody,
I'm developing a Swing app with a main Frame which contains multiple
JInternalFrames.

I need to make something like this:

We have 2 JInternalFrame: intf1 and intf2.
intf1 contains some JTextFields and some JButtons.
intf2 contains a JTable.

On intf1, when button Button2 is clicked, intf2 must open. On intf2
there are some values on a JTable, which should be passed to the
calling JInternalFrame (in this case intf1) writing them on its
JTextField.

Regarding the intf2 opening on Button2 click, I was able to do that
accessing the main Frame (let's call it frmMain) in this way:

if (frmMain.intf2 == null) {
frmMain.intf2 = new JInternalFrame("Internal Frame
2",true,true,true,true);
frmMain.intf2.setContentPane(new IntFrame2());
frmMain.intf2.setBounds(12, 9, 500, 400);
frmMain.jDesktopPane1.add(frmMain. intf2);
frmMain.jDesktopPane1.updateUI();
}
frmMain.intf2.show();

What do you think about it?


As long as this is done on the EDT, it's fine. It should be because the
ActionListener is called on the EDT.

Regarding the access to the calling JTextField I don't know...
How can I do? I hope you can help me


Where is the JTable from intf2 that you mentioned? You need to make it
or access it, then copy some values out and set them in intf1. Use the
code above to do it. Right after you create intf2, access (or make) the
JTable, and set some values in intf1.

These frame are bound together rather tightly, imo. At some point you
might want to make a PrimaryFrame and a SecondaryFrame as interfaces,
and create some classes based on interfaces. Then have the code above
deal only with interfaces. It's make both testing easier once this
program grows beyond the non-trivial stage, as well as making future
modification easier too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top