Okay, so I am not sure exactly what information I need to give, but I will try...
I have a program called "QuestionBuilder" that will allow the user to enter several fields for a trivia question and some answers, then hit the 'Next' button. They will also be able to hit the 'Previous' buttons, but the Previous button is disabled unless you are on any element after the first (a preventative measure). Previous goes to the last element in the Array, Next moves forward. Here is how it is set up:
questionIndex is my counter. It starts at 0.
ArrayList questionSheet is initiated (errors are returned but they don't stop the program from running--can anyone explain this?)
User enters question and answer fields, then hits 'Next' button.
Upon hitting the Next button, it'll do the following:
My Question Class Constructor:
My Question Status Checking Method:
My 'Previous' button code:
My 'Next' button code:
Some other things to explain:
hasNext does exactly what it should--it checks to see if the questionIndex is less than the size of the Array - 1. If there is any difference between the two numbers, it has a next location in the Array.
setQuestionStatus() basically is run at the end of the major methods that might change any of my booleans. The booleans are updated, which then focuses on enabling/disabling buttons and making sure my counts are correct and such.
setCurrentQuestion() takes the questionIndex AFTER it is being incremented or decremented and will set the fields to the question that it pulls out of the area (does a simple questionSheet.get(questionIndex) call).
Alright, so information out of the way (I think), I'll tell you what it is doing...
When I hit Next, it should:
- Check to see if it has a next question (should have done this already but just simplifying in this list)
- If it does, save existing question, clear the fields, then repopulate the fields with the new info
- If it does not, add existing question to array, clear fields
When I hit Previous it should:
- Check to see if the current question has been added to the Array (I can't use a simple indexOf because it could have been changed -- THIS IS THE TRICKY PART FOR ME)
- If it does, save the existing question, clear the fields, and move on
- If it does not, add the question to the area, clear the fields, and move on
- Repopulate the fields with the values for the previous question
- Check to see if it is the first question and disable the previous button if so
My program works great. I hit next, next, next, and I watch the number of the question go up and up (the title label which I have in my swing). PERFECT. Then I hit previous, previous, previous... also working like a charm! However, somewhere along the way, it skips numbers. I think the "isLastQuestion" boolean I have set up is not working properly. I have it call at the end of the buttons to replace the values, and check for the Array size - 1, as I think it should... but somewhere it starts cutting out, and I cannot find a
pattern.
There is another problem, but I want to find the fix to this one first... if anyone could help, I would STRONGLY appreciate it. I know this has been a lot of code and text to read through!