0

As the title say, I actually want to know how one JFrame form can know the windowListening status of other JFrame form.

Might it be confusing, but I can clarify it.

I have a main JFrame form which call 2 other JFrame form. So whenever one JFrame form get closed, it call back the main JFrame form to setVisible(true) and set itself dispose().

But I want to know the status of each other JFrame form individually. All I want is:

  1. If my 1st JFrame is closed, it shud check other JFrame status. If that other JFrame is Activated, then the main JFrame form will not be called. If the other JFrame is Closed or already disposed(), then it shud call the main JFrame to setVisible(true).

I hope u get it. Can someone plz help me to get thru this.

Thanks in Advance.

See: All three JFrame forms are in same package. I'm a newbie in java, so excuse my writing notations. :p

androizer
  • 77
  • 9
  • 1
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 22 '15 at 14:53
  • JFrame is a top-level container, it is unlikely that your application needs more than one of them (but not impossible). Generally you create one top-level container and then use JDialog or some other non-top level container for other parts of your application. Are you sure you need more than one JFrame in your application? – Michael Jun 22 '15 at 14:59
  • @Michael, Its just the way I started my project. Its actually P2P project, so we've been told to make new JFrame whenever there is any new visual iteration to ur project. Example: I have a main JFrame, which have the options to launch either Server, Client or both (for debuggable purpose). So obviously Server and Client need different different JFrame which I've being doing from the day I started my project. Is this a good/bad practice?? Answer: This is why I join StackOverFlow/StackExchange.!! :D Experience is all that I have to gain. ;) – androizer Jun 22 '15 at 15:15

1 Answers1

0

Make (2) singleton JFrame classes e.g. public class JFrame1 extends JFrame {}. Then you can always call JFrame1.getInstance().isClosed() or whatever you wish. If you're unsure how this would work, google 'java singleton design pattern' =)

Roel Strolenberg
  • 2,922
  • 1
  • 15
  • 29
  • I've somehow edited the OP, can u take a look and see if that make sense. I'm not an experienced one in writing notations correctly. Edit: As I've seen ur reply, I'm coding in NetBeans, so my classes are already extending JFrame, how can I extend another one when its not possible.. – androizer Jun 22 '15 at 14:38
  • I don't have permissions to edit OP, it's maybe a bit ill-posed, but I understand the question. – Roel Strolenberg Jun 22 '15 at 14:43
  • I've searched bout the java singleton, but unfortunately, I didn't get it. May b its way out of my league. Is there any other work around?? – androizer Jun 22 '15 at 14:56
  • There is another way, though I advise you to use a singleton. Pass a reference of your main frame to your other frames. So constructor for JFrame1 would be: `public JFrame1(JFrame mainFrame)`. In your main frame pass an object of itself to JFrame1: `JFrame1 frame1 = new JFrame1(this);`. This is all very dependent on your code though. You could also make EVERYTHING static I suppose and just call `if (MainFrame.visible) {...}` But I strongly suggest never doing this with frames. – Roel Strolenberg Jun 22 '15 at 15:02