1) It is good design to separate your data from the presentation. Are you doing this already? What I mean is you should be looking to store answers in an object outside of the jPanel class.(As 'Hovercraft Full Of Eels' suggested).
1) It is good design to separate your data from the presentation. Are you doing this already? What I mean is you should be looking to store answers in an object outside of the jPanel class.(As 'Hovercraft Full Of Eels' suggested) 2) Consider making the data objects Serializable objects.
If you're not planning on storing the data across a network or anything complicated/peculiar this should work out for you as it will facilitate save/load operations 3) Once you have your data separate from the GUI a check for changes becomes very easy. Assume that on any operation that takes you away from the page it "saves" its state. If the current state is different from the saved state then prompt the user to save (if it doesn't by default).
Great minds think alike. 1+ – Hovercraft Full Of Eels Jun 28 at 21:47 Thank you for your valuable comment but I m not familiar with serialization. I did one thing which I would like to share.
Please give your suggestion on that. For each question I have separate saving and opening function I am saving name of all components and values in a notepad file and then retrieving the values from it. I am able to save and retrieve but isnt their any other simple way so that it could be common for all questions – Gaurav Jun 29 at 0:04 I tried to answer 5 components and save it in notepad.
And on loading it I am able to get all those components filled. Its working. But its quite hard coded and yes of course bad programming.
But I have some time limitations so can you suggest anything similar to this logic. If by some function or method I could know all the components variable name present in my JPanel. Like all the 15-20 combo-box and same no of text-box.
I could make a function which can be common for all. – Gaurav Jun 29 at 0:08 The idea of serialization is you declare an object serializable. There's a few methods you must implement at this point which allow you to export and import the object similar to how you would read/write to filesIf you were able to organize your questions and data into container objects (List object perhaps) then you could declare it serializable and store it in a file.
Whent he application reloads you could load the file and it would read from the data collection back into the appropriate UI elements. Googling serialization is a good start to learn how to use it. – TheCapn Jun 29 at 14:32.
I have to wonder if you've created this program primarily as a NetBeans-generated GUI without first creating the non-GUI guts of the program. So first I have to ask, have you divided out your program logic from your GUI code a la MVC (model-view-controller) or one of its many variants? If not then this should be your first order of business, since in truth the saving and recovery of the data should have nothing to do with its GUI representation.
The key to solving your problem is going to be good object-oriented programming design. Consider for instance creating a non-GUI Question class that has several fields including a String question field, an ArrayList of possibleAnswers and a field String for the correctAnswer. Consider having an ArrayList of these Questions (ArrayList) for each chapter and a collection of the Chapters.
Then you will need to figure out the best way for you to save the questions and the users answers. This may be via serialization, XML (JAXB? ), or my recommendation: a database.
Only after you've figured out all of this should you worry about how to integrate a GUI around your non-GUI logic code which will be the GUI's "model". Edit Replies to your comments: Sorry I havent provided enough info of my project. I m doing it in NETBEANS 7 GUI.
I guess netbeans java programs are MVC Sorry, no. If all you do is create a GUI with NetBeans you will be creating an unwieldy god-class. To have good MVC you must design it that way from the beginning.
Again that means creating your program logic before creating the GUI which in your case includes creating multiple non-GUI classes as I've indicated above. There is no "automatic" MVC in NetBeans. I may be wrong as I don't know much about MVC.
Yes, unfortunately you're wrong. Please read about it: Model-View-Controller. This will help you with your current and future design.As of now I am able to save and retrieve.
But I want your suggestion on that. It is quite hardcoded for each question. And that should probably be fixed as you do not be hard-coding the questions.
In fact the question text shouldn't even be part of the code but part of the data. Consider having the question in a comma-delimited text file or database. I tried to answer 5 components and save it in notepad.
And on loading it I am able to get all those components filled. Its working. But its quite hard coded and yes of course bad programming.
But I have some time limitations so can you suggest anything similar to this logic. If by some function or method I could know all the components variable name present in my JPanel. Like all the 15-20 combo-box and same no of text-box.
I could make a function which can be common for all Sorry, I wish I could, but I can't, not unless you first fix your design issues. Good luck!
Sorry I havent provided enough info of my project. I m doing it in NETBEANS 7 GUI. I guess netbeans java programs are MVC.
Model depends on designing. View how we see and Controlling by writing functions for each work. I may be wrong as I don't know much about MVC.As of now I am able to save and retrieve.
But I want your suggestion on that. It is quite hardcoded for each question. I am saving name of all components and values in a notepad file and then retrieving the values from it.
I am able to save and retrieve but isnt their any other simple way so that it could be common for all questions – Gaurav Jun 28 at 23:57 I tried to answer 5 components and save it in notepad. And on loading it I am able to get all those components filled. Its working.
But its quite hard coded and yes of course bad programming. But I have some time limitations so can you suggest anything similar to this logic. If by some function or method I could know all the components variable name present in my JPanel.
Like all the 15-20 combo-box and same no of text-box. I could make a function which can be common for all – Gaurav Jun 29 at 0:12 @user815576: please see edit to my answer. – Hovercraft Full Of Eels Jun 29 at 0:49 Thanks for all this info.
I will surely go through M-V-C. But due to time limitations I fear I have to complete this quickly. I will take this project for further development and use MVC for sure.
Till then can you help me on this. I created two functions saving and opening in one question class. There is a button on the panel for opening.
If I click this I am able to load file. But if I run open from menu bar it doesn't load. I am able to go to opening function of the question as I checked it with System.out.println() in my function.
But I am unable to change anything on my panel. Please reply – Gaurav Jun 29 at 1:38 I also added my codes for opening(). When I click menu bar.. it does not show the results.
It loads as the Sopln("") and Sopln("OUT") shows in output that on clicking menubar open it goes to the function. But the relevant changes are not done. Eventhough same function is called in both case – Gaurav Jun 29 at 1:55.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.