load a frame once

Im using the code below to load a frame every time a user opens the class file concerned with the following code. But I want the frame only to be loaded once, just when the user loads the class for the first time, and the for the class to be dynamically updated. The if statement im tyring to use throws an error when a second user trys to concurrently load the class file. Any help would be great, thanks.

public F(int NO){
            if(NO == 0){//this flag causes an error
            dis = new TextArea(20 , 10);
                  add("Center" , display);
          resize(300 , 150);
Who is Participating?
objectsConnect With a Mentor Commented:
would a Hashtable on frames help you:

private Hashtable frames = new Hashtable();

public F getFrame(int no)
   Integer _no = new Ineteger(no);
   F result = (F) frames.get(_no);
   if (result==null)
      result = new F(no);
      frames.put(_no, result);
   return result;
you need to change the code that actually create F.
Keep an instance to F, and reuse it.
RonayneAuthor Commented:
Im creating different instances of f for different parameters passed in variable NO
does the question mean the instance of the frame can be open one at a time?

i try this using JInternalFrame.

-doDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); for the frame
-when you want to frame to be open, use setVisible(true);

i successfully restrict the frame to be loaded one at a time.

Feel free to discard this comment if this is not what you asking ;)

-Child that so pissed off!-
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.

All Courses

From novice to tech pro — start learning today.