Results 1 to 3 of 3
  1. #1
    BeRniTo is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Question 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 03:06 PM.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Google two patterns.
    Command pattern.
    Mediator pattern.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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

  1. Unable to display JDialog from JFrame
    By jv5 in forum NetBeans
    Replies: 2
    Last Post: 02-04-2009, 05:33 AM
  2. Returning data from a JFrame/JDialog?!
    By Joe2003 in forum AWT / Swing
    Replies: 6
    Last Post: 01-08-2009, 01:14 AM
  3. Communicate between Windows and UNIX
    By nwboy74 in forum Networking
    Replies: 10
    Last Post: 11-04-2008, 09:53 PM
  4. Communicate vb.NET with Java
    By cachi in forum Advanced Java
    Replies: 1
    Last Post: 08-02-2007, 01:41 AM
  5. problems with jDialog in a JFrame
    By bbq in forum AWT / Swing
    Replies: 1
    Last Post: 07-05-2007, 05:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •