Results 1 to 3 of 3
Thread: Communicate JFrame with JDialog
- 08-30-2009, 06:52 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 2
- Rep Power
- 0
Communicate JFrame with JDialog
Hello everybody! :)
I'm having problems when trying to communicate a JFrame with a modal JDialog child of it.
Here is the thing: the JFrame has a button that opens the JDialog which has a JTable and 2 buttons: "Accept" and "Cancel".
What I want to do is that when the Accept button is pressed some information is sent to the JFrame, but if the Cancel button is pressed nothing is to be done. Also, there are more than one JFrame that instantiate the JDialog, so calling a public operation from the JDialog to its father when it closes won't work because a cast using the JFrame's father name is needed.
I've "googled" a lot and couldn't find much about communication between windows (what surprises me).
I've come with a solution which I don't know if it's correct. I've created an ActionListener where I update components of the JFrame with the information needed getting it through a public operation of the JDialog. The creation of this listener is done within the call to another public operation of the JDialog called setListener which only adds the listener to the Accept's action listeners.
The idea is: create the JDialog, call setListener passing the ActionListener and then set the JDialog visible. Something like:
Java Code:MyJDialog md = new MyJDialog(); md.setListener(new ActionListener() { public void actionPerformed(ActionEvent e) { info = d.getInfo(); // update components using the information } }); md.setVisible(true);
This works great but I don't know if its correct (good programming practice?) and I can't belive there's no already-supported way within Java to do something like this.
Sorry about my English, I'm from Uruguay. :P
Thanks! :)Last edited by BeRniTo; 08-30-2009 at 02:06 PM.
- 08-30-2009, 08:47 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Google two patterns.
Command pattern.
Mediator pattern.
-
I kind of like the way the original poster is solving his problem, by allowing a containing class to add a controller. r035... do you consider his solution to be bad form?
Similar Threads
-
Unable to display JDialog from JFrame
By jv5 in forum NetBeansReplies: 2Last Post: 02-04-2009, 04:33 AM -
Returning data from a JFrame/JDialog?!
By Joe2003 in forum AWT / SwingReplies: 6Last Post: 01-08-2009, 12:14 AM -
Communicate between Windows and UNIX
By nwboy74 in forum NetworkingReplies: 10Last Post: 11-04-2008, 08:53 PM -
Communicate vb.NET with Java
By cachi in forum Advanced JavaReplies: 1Last Post: 08-02-2007, 12:41 AM -
problems with jDialog in a JFrame
By bbq in forum AWT / SwingReplies: 1Last Post: 07-05-2007, 04:14 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks