public class ApplicationSingleton {
static private ApplicationSingleton instance;
private ItagTreeView.TreeParent chart;
public static ApplicationSingleton getInstance() {
if (instance == null) {
instance = new ApplicationSingleton();
}
return instance;
}
private ApplicationSingleton() {
super();
}
public void SetCurrentChart(ItagTreeView.TreeParent tp) {
chart = tp;
}
public ItagTreeView.TreeParent getCurrentChart() {
return chart;
}
}
Now to talk about some parts of this class.
- We include a private variable of our class called "instance"
- From our application code we make calls to getInstance(), such as this:
TreeParent tp = ApplicationSingleton.getInstance().GetCurrentChart(); The first time we call getInstance it will make an instance of this class. - By using setCurrentChart() we can store our variables in view1 and in view2 we can use getCurrentChart.
Easy, right? :) If you have any questions or comments I'd love to hear them!
No comments:
Post a Comment