Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

interaction between JFC internal frames

Hi there,

     I'm trying to set up a program that has a similar interface like eudora. It has one main
JDesktopPane, in which 3 internal frames are contained. What I want to do is to allow
interaction between the internal frames. For example, if I choose an item from the list
in internal frame #1, I want to update some information in internal frame #2. And if I click
on a tree selection in internal frame #2, it will display the appropriate information in
internal frame #3.

The problem is that I can't seem to use the desktop pane to control these interactions.
Each mouse click event is sent to the corresponding internal frame, and the event will
not be passed to the main desktop pane. Is there a way I can let each internal frame
inform the desktop pane that it has been clicked? Can you guys think of a better interaction
scheme for the program?

Any ideas would be appreciated. Thanks a lot in advance!

- Tony
0
sailwind
Asked:
sailwind
  • 4
  • 2
  • 2
  • +1
1 Solution
 
shchukaCommented:
Can you have two methods in the JDesktopPane, say

public void ListItemInFrame1Chosen(whatever you need to pass)

public void TreeItemInFrame2Selected(whatever you need to pass)

and call this methods from the corresponding events of the corresponding internal frames?
0
 
sailwindAuthor Commented:
I suppose that's one way of doing it. To do that, I'll have to pass
the calling JDesktopPane class itself to every internal frame so
that the corresponding JDesktopPane methods can be invoked.
I really would like to avoid this, the organization of the code would
be very messy and not very object oriented. Anyonelse got an
idea?
0
 
gadioCommented:
Tony, you can create a new event(s) (for example MyUpdateEvent), and upon creation of the internal frames, make each of them a listener to that event from the other two (or N) frames. Each of the frames will have an event handler that would deal with the specific event.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gadioCommented:
.... And when a frame is changed in s certain way it will fire the event that indicates how was it changes and some relevant info to the other frames. You mat want to make the desktop listenr to some of the events as they may affect it.
0
 
sailwindAuthor Commented:
Okay, let me try to visualize what you're saying.
We have 1 main desktop, 2 internal frames A&B
We also have a custom event called MyUpdateEvent()

We let the desktop and the internal frames all listen to MyUpdateEvent
When a selection is made in one of the frame, it will fire a MyupdateEvent
with the relevant information such as what was selected.
The desktop or the other internals frames will then get notified because they're
listening, and can take action accordingly.

Is this what you were saying?

Thanks for the help
- Tony


0
 
fontaineCommented:
For me, the best option would be to make use of inner classes for the implementations of
the internal frames. Actually, your 3 internal frames are part of one single system and it makes
sense, in the OO paradigm, to have this system defined as one single class. The
skeleton code below shows you what this approach would give. Imagine that there is a button
in the first frame which, when clicked displays a "Hello" message in the second frame.

public class Eudora ... {

    private JInternalFrame1 frame1 = ...
    private JInternalFrame2 frame2 = ...
    private JInternalFrame3 frame3 = ...

    private class JInternalFrame1 extends JInternalFrame {

        private void actionPerformed(ActionEvent e) {
            frame2.sayHello();
            return;
        }
    }


    private class JInternalFrame2 extends JInternalFrame {

        public void sayHello() {
            //...
        }
    }

    private class JInternalFrame3 extends JInternalFrame {

    }
}

Tutorial on inner classes:
http://java.sun.com/docs/books/tutorial/post1.0/whatsnew/inner.html

Tell me if this is an answer.
0
 
sailwindAuthor Commented:
Both suggestions sound pretty good. Please allow me some time
to try them out.
0
 
sailwindAuthor Commented:
Okay, I tried out the inner class way. It works great and allows very good
interaction between the Internal Frame components without having to create
a separate event and event listener. The event listener would probably be
more handy if I wanted to update more than one window at a time. But right
now the inner class seems like the way to go. Thanks fontaine, please lock
the question so I can reward the points.

- Tony
0
 
fontaineCommented:
For me, the best option would be to make use of inner classes for the implementations of
     the internal frames. Actually, your 3 internal frames are part of one single system and it makes
     sense, in the OO paradigm, to have this system defined as one single class. The
     skeleton code below shows you what this approach would give. Imagine that there is a button
     in the first frame which, when clicked displays a "Hello" message in the second frame.

     public class Eudora ... {

         private JInternalFrame1 frame1 = ...
         private JInternalFrame2 frame2 = ...
         private JInternalFrame3 frame3 = ...

         private class JInternalFrame1 extends JInternalFrame {

             private void actionPerformed(ActionEvent e) {
                 frame2.sayHello();
                 return;
             }
         }


         private class JInternalFrame2 extends JInternalFrame {

             public void sayHello() {
                 //...
             }
         }

         private class JInternalFrame3 extends JInternalFrame {

         }
     }

     Tutorial on inner classes:
     http://java.sun.com/docs/books/tutorial/post1.0/whatsnew/inner.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now