I am making a GUI and I have almost 10 frames each accepts data from user. I want to save this data in one object. I am wondering how to do that.like you make one object in main and access all the functions from there and store all the data in this one object.
Asked
Active
Viewed 379 times
0
-
please read this http://stackoverflow.com/help/how-to-ask – sanoj lawrence Jan 08 '15 at 09:31
-
Don't create multiple jframes. Reuse the same one. Create multiple `JPanel`. Use tabbed panels if you want all the screens at the same time. – Sorter Jan 08 '15 at 09:31
-
Actually I have 2 classes one road(edges) and one city(vertex) and a Graph class that access both classes. I want to work with only Graph class object. All I want is that when i press submit button in different places all data should be stored in one object. – Faiqa Babar Jan 08 '15 at 09:37
-
Google "model view controller pattern" – BarrySW19 Jan 08 '15 at 09:44
-
See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jan 08 '15 at 11:23
1 Answers
1
If the all data are "related to one object," you can make a class to represent this object; either
make the class static, with all elements inside it
or make the class a singleton
public class ClassicSingleton { private static ClassicSingleton instance = null; protected ClassicSingleton() { // Exists only to defeat instantiation. } public static ClassicSingleton getInstance() { if(instance == null) { instance = new ClassicSingleton(); } return instance; } }

Catalina Island
- 7,027
- 2
- 23
- 42

abdotalaat
- 735
- 7
- 10