PDA

View Full Version : مبتدی: check instance of class in JRE



jeus
جمعه 27 شهریور 1388, 03:17 صبح
سلام دوستان میدونم که این سوال خیلی ساده است و من هم یادم قبلا دیده بودمش اما الان هرچی فکر کردم یادم نیومد
چجوری میشه فهمید که تا حالا از یک کلاس instance گرفته شده یا نه
اگه یادم نرفته باشه باید یکی از اینها باشه SYSTEM , Garbage Collection , JRE
از همه دوستان ممنونم


ما بیداریم

jeus
جمعه 27 شهریور 1388, 13:38 عصر
دوستان مشکل حل شد


public class PNLSpcMaster {

/**
* This class attribute will be the only "instance" of this class
* It is private so none can reach it directly.
* And is "static" so it does not need "instances"
*/
private static PNLSpcMaster instance;

/**
* Constructor make private, to enforce the non-instantiation of the
* class. So an invocation to: new PNLSpcMaster() outside of this class
* won't be allowed.
*/
private PNLSpcMaster(){} // avoid instantiation.

/**
* This class method returns the "only" instance available for this class
* If the instance is still null, it gets instantiated.
* Being a class method you can call it from anywhere and it will
* always return the same instance.
*/
public static PNLSpcMaster getInstance() {
if( instance == null ) {
instance = new PNLSpcMaster();
}
return instance;
}
....
}



private void jButton (java.awt.event.ActionEvent evt) {
jtabbedPanel.addTab("reg",PNLSpcMaster.getInstace());
}