Solved

interaction between JFC internal frames

Posted on 1998-08-03
9
292 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
.... 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 3

Author Comment

by:sailwind
Comment Utility
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
Comment Utility
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
Comment Utility
Both suggestions sound pretty good. Please allow me some time
to try them out.
0
 
LVL 3

Author Comment

by:sailwind
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 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

12 Experts available now in Live!

Get 1:1 Help Now