Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tracking java objects

 
ramdas pradeep kumar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai there,
how to know whether an object of a class presently invoked. for example i am opening a frame by clicking a button. without closing that i opened another frame. now how can i know whether a frame is opened previously.

pradeep
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ramdas
The first thing comes to my mind is you can extends the Frame/JFrame and make your custom frame object and make it "singleton".
In case you are not aware of how singleton works...
public class MyFrame extends JFrame {
private static MyFrame myFrame;
private MyFrame() {
}
public static getInstance() {
synchronized(MyFrame.class) {
if ( myFrame == null) {
myFrame = new MyFrame();
}
}
return myFrame;
}
}

Please let me know if I unncessarily confused you.
Also, this is what I get from top of my mind. I don't know if you can somehow make Frame "modal" as Dialog boxes...It has been while I did any UI..
Regards
Maulin
 
Gayathri Prasad
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How abt statica variable which keeps the count of the object. For frames when we close the frame then we decrement the static variable. This jus my personal opinion feed back would certainly help me.'
Cheers,
Gaya3
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a PB project with MDI interface and a lot of pop ups. When closing the frame we had to know the status of all the subwindows. So we made a window manager with methods to open and close windows that also kept a collection of what's open.
Nowadays I'd use a pub-sub style solution where windows register themselves for "about to close" events. If a window was not in a closeable state, it could respond in a way that makes the publisher stop trying. My Messaging Patterns page mentions this technique. You'd have to write your own publisher - the standard Observable doesn't act on results from events it sends out.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did a PB project with MDI interface and a lot of pop ups. When closing the frame we had to know the status of all the subwindows. So we made a window manager with methods to open and close windows that also kept a collection of what's open.
Nowadays I'd use a pub-sub style solution where windows register themselves for "about to close" events. If a window was not in a closeable state, it could respond in a way that makes the publisher stop trying. My Messaging Patterns page mentions this technique. You'd have to write your own publisher - the standard Observable doesn't act on results from events it sends out.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic