JFrame vs JInternalFrame for many windows application

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.  
thanyajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DanninCommented:
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
hotsmileCommented:
dannin ,
you are wrong
must be
if (postIt==null)
{
}
not =
0
DanninCommented:
thanxs for the correction doing vb6 atm at work got a bit mixed up=)
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

CEHJCommented:
You can use the desktop pane as the area in which to place the internal frames
0
objectsCommented:
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
thanyajAuthor Commented:
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
objectsCommented:
> 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
thanyajAuthor Commented:
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
objectsCommented:
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
thanyajAuthor Commented:
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
objectsCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thanyajAuthor Commented:
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
objectsCommented:
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
thanyajAuthor Commented:
Thank you very much for an idea.
I will try and tell you later ;)
0
thanyajAuthor Commented:
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
objectsCommented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.