Solved

interaction between JFC internal frames

Posted on 1998-08-03
9
293 Views
Last Modified: 2013-11-23
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
Comment
Question by:sailwind
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1230824
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
 
LVL 3

Author Comment

by:sailwind
ID: 1230825
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
 
LVL 6

Expert Comment

by:gadio
ID: 1230826
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
 
LVL 6

Expert Comment

by:gadio
ID: 1230827
.... 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:sailwind
ID: 1230828
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
 
LVL 5

Expert Comment

by:fontaine
ID: 1230829
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
 
LVL 3

Author Comment

by:sailwind
ID: 1230830
Both suggestions sound pretty good. Please allow me some time
to try them out.
0
 
LVL 3

Author Comment

by:sailwind
ID: 1230831
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
 
LVL 5

Accepted Solution

by:
fontaine earned 200 total points
ID: 1230832
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now