Solved

interaction between JFC internal frames

Posted on 1998-08-03
9
294 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse shortcuts 9 55
web services creation SOAP vs REST 5 42
tomcat not starting 6 45
jboss wildfly 10.1 10 94
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 first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

810 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