• Post Reply Bookmark Topic Watch Topic
  • New Topic

WindowListener Singleton Method  RSS feed

Gregg Bolinger
Ranch Hand
Posts: 15304
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application that spawns several JFrames. I have a windowTracker class that extends WindowListener and I use this class to track all my JFrames. The way I am using it is basically, when a window opens the WindowEvent for windowOpened() places a reference to that JFrame in a Hashmap along with the name of the JFrame. And in the windowClosing() I remove the window from the hashMap.
I am also using the Singleton method when creating my JFrames, meaning I have a getInstance() method that returns my JFrame object to whoever needs it. Here is my singleton method pseudo code:

Ok, everything works except, when I close any of the JFrames, I need to set theOnlyFrame back to NULL. And I would like to do this on the windowClosing() method. However, without using an IF statement and statically checking each frame I plan to create, I don't know how to do it.
Here is the code for my windowTracker class
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!