Solved

JFrame vs JInternalFrame for many windows application

Posted on 2003-11-13
16
602 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
  • 6
  • 6
  • 2
  • +2
16 Comments
 
LVL 2

Expert Comment

by:Dannin
Comment Utility
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
Comment Utility
dannin ,
you are wrong
must be
if (postIt==null)
{
}
not =
0
 
LVL 2

Expert Comment

by:Dannin
Comment Utility
thanxs for the correction doing vb6 atm at work got a bit mixed up=)
0
 
LVL 86

Expert Comment

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

Expert Comment

by:objects
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 92

Expert Comment

by:objects
Comment Utility
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
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much for an idea.
I will try and tell you later ;)
0
 

Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

743 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

16 Experts available now in Live!

Get 1:1 Help Now