?
Solved

JFrame vs JInternalFrame for many windows application

Posted on 2003-11-13
16
Medium Priority
?
650 Views
Last Modified: 2010-07-27
From my last question that I'm really mad to press the accept button. (Totally Newbie Here!)

The new problem is...

I want my program to be able to create and delete PostItNote.
If I delete PostItNote (click button on a note), I want to destroy the instance in order to reuse that instance again for new PostItNote.
How can PostIt Class know that PostItNote is destroyed?
So, They can create new PostItNote object for that instance.

I'm note sure that I explain clearly or not!  So, this is example.

In PostIt Class -> create note[0], note[1], note[2]   = new PostItNote()
In PostItNote Class -> delete note[1]

Then, PostIt Class -> create note again
How do PostIt Class know that It should use  note[1] = new PostItNote();

Thank you very much.

PS. If you know the web sites or books to recommend me, you're very welcome to ;)
------------------------------------------------------------------------------------------------------
Comment from CEHJ
Date: 11/13/2003 05:28AM PST
 Comment  

>>But when I close one of Jframes -> all windows are closed (exit).

That's one of the reasons i suggested not using an array of JFrames. They are not really designed to be used in the way you want to use them as they don't behave independently. I would use JInternalFrame

------------------------------------------------------------------------------------------------------
Comment from thanyaj
Date: 11/13/2003 06:06AM PST
 Your Comment  

I wish I could use it. But after reading document, I'm still wonder that can JInternalFrame stay outside DesktopPane?
Because I don't want all PostItNote to be stayed in a Big window. I want to move it around desktop.  
0
Comment
Question by:thanyaj
[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
  • 6
  • 6
  • 2
  • +2
16 Comments
 
LVL 2

Expert Comment

by:Dannin
ID: 9739515
you can destroy it by making the instance equal to null

for example

potIt=null;

then to check it it's null quite simple really. unless u have an array of notes then you'll have to pass it through a loop if not and u know your post do the following.

if (postIt=null)
{
   //then do something here
}

hope this helps =)
0
 

Expert Comment

by:hotsmile
ID: 9739717
dannin ,
you are wrong
must be
if (postIt==null)
{
}
not =
0
 
LVL 2

Expert Comment

by:Dannin
ID: 9739728
thanxs for the correction doing vb6 atm at work got a bit mixed up=)
0
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!

 
LVL 86

Expert Comment

by:CEHJ
ID: 9742003
You can use the desktop pane as the area in which to place the internal frames
0
 
LVL 92

Expert Comment

by:objects
ID: 9742080
No need to use an internal frame, just use a WindowListener to track when windows are closed.
Of if the same button opens the same window each time, then don't dispose the window and just hide/show it appropriately.
0
 

Author Comment

by:thanyaj
ID: 9743121
I can't use note[i]==null to check that the JFrame is close? There is no effect.
If I create new PostItNote 0,1,2,3  -> close #1 , Then I create new note again, it is #4 (not #1)

Hide/Show note is one option that i want to do.
But I also want to save note into file. So, if i delete notes, i want to delete file as well.
When I create note, I also want do create note file.

PS.
I may design class improperly. Because my background is C programming language.
I have PostIt class: create PostItNote (Array of Object PostItNote)
When I want to close PostItNote-> I just do nothing except clicking the close button.
What else I should do after I close note?
0
 
LVL 92

Expert Comment

by:objects
ID: 9743143
> So, if i delete notes, i want to delete file as well.

Then use a WindowListener to delete the file when the window is closed
I included a link on this in your other q.
0
 

Author Comment

by:thanyaj
ID: 9744525
To implement this, I use arrayList instead of array. (i hope that life will be easier)

BUT .... I still have no idea to check that if the PostItNote object is disposed ?
How can I do?  This is some part of my code.

PostIt Class (Extend JFrame)
==========================================
    PostIt() {

    newnote = new JButton ("New Note");
    // Cretae new note
    newnote.addActionListener(new ActionListener()
   {
      public void actionPerformed(ActionEvent e)
      {
          noteList.add(new PostItNote());
      }
    });

    test = new JButton("test");
    test.addActionListener(new ActionListener()
   {
      public void actionPerformed(ActionEvent e)
      {
          /******** check if any item in list is null **********/
          /***** I CAN NOT DETECT THE DISPOSED OBJECT *****/
          for(int i=0;i<noteList.size();i++) {
              if (noteList.get(i).equals(null)) {
                JOptionPane.showMessageDialog(null, (i + " is null"));
              }
          }
    });

    }

    public static void main (String[] args) {
        PostIt p = new PostIt();
        noteList = new java.util.ArrayList();
    }
======================================
PostItNote Class (extend JFrame)
- just create GUI
+ WindowListener

    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            dispose();
        }
        });
0
 
LVL 92

Expert Comment

by:objects
ID: 9744547
You can use a WindowListener to perform any processing that is required when a window is closed (such as removing it from your list, or saving details to file). Exactly what difficulty are you having with using one?
0
 

Author Comment

by:thanyaj
ID: 9744583
Because i don't know how to call any instance in PostIt Class from the method in PostItNote
There is no PostIt object to use ???
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 9744610
The simply provide one to your listener,

public class MyListener implements WindowListener
{
   private PostIt Parent;

   ....
}



or make the PostIt class itself your window listener.

public class PostItimplements WindowListener
{
   ....
}
0
 

Author Comment

by:thanyaj
ID: 9744696
The Exactly question is

In PostItNote
=========
this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            // How can i use noteList (belong to class PostIt) ???
            // just like noteList.remove(i);
        }
        });

0
 
LVL 92

Expert Comment

by:objects
ID: 9744771
If you are using an inner class as a listener then it would be better placed in the PostIt class (or make the PostIt class itself the WindowListener). Or alternatively make it a seperate class as I outlined above.
0
 

Author Comment

by:thanyaj
ID: 9744797
Thank you very much for an idea.
I will try and tell you later ;)
0
 

Author Comment

by:thanyaj
ID: 9757691
Finally, I can figure out.
I create Static Method in parent class.
So, I can call method easily.

Instead of

public class MyListener implements WindowListener
{
   private PostIt Parent;

   ....
}

I use
public class MyListener implements WindowListener
{
    PostIt.remove(i);
}

;)
0
 
LVL 92

Expert Comment

by:objects
ID: 9759751
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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.
Suggested Courses

719 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