aspose file tools*
The moose likes Beginning Java and the fly likes How do i check if an object has been created? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do i check if an object has been created?" Watch "How do i check if an object has been created?" New topic
Author

How do i check if an object has been created?

George Papadopoulos
Greenhorn

Joined: Apr 13, 2004
Posts: 3
Hallo!
In my application if a button is pressed a new object is created.
i want my button to stay enabled but if the user presses it again i want to display an error message.
what do i put into the if statement to check if the object has already been created?
Thanx a lot!
Mike Southgate
Ranch Hand

Joined: Jul 18, 2003
Posts: 183
sounds to me like your looking for a variation of the singleton pattern. But the easiest way is to simply create a has-a relationship with the caller and then check it for == NULL
ms


ms<br />SCJP, SCJD
sever oon
Ranch Hand

Joined: Feb 08, 2004
Posts: 268
You can check the reference to the object for null:

It's bizarre to me that you specifically said you want to leave the button enabled even though it will definitely result in an error if the user presses it. This sounds like a pretty hostile UI. Disable it, and enable it only when pressing it won't result in an error.
sev
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do i check if an object has been created?