Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

interaction between JFC internal frames

Posted on 1998-08-03
9
Medium Priority
?
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
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 800 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

Technology Partners: 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!

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

730 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