Skip to content
Advertisement

traverse an array in GUI Java

I am doing a questionnaire with questions and written answers. I need that when adding the answer, press the main button, tell me if it is correct or not and show me the other question of the array, until the array is finished. Here I upload the whole code.

JavaScript

Advertisement

Answer

You have the right idea, but you need to process the questions one at a time, not all at once inside the ActionListener.

One way to approach this is to keep track of the question outside of the action listener, in this example we use int questionCounter = 0; to keep track of the current question, then we can remove the for loop and process the questions one at a time. Here is a simple example of how it could work using your code, note how we reset the fields and add the next question every time the previous question is answered.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement