I can not understand how to implement tests of a closed type with one variant of answers (radiobutton). I do not know how to implement the transition from one question to the second. Example (just for understanding what I need):

Question 1 :
answer 1
answer 2
answer 3
Answer 4.
OK button.

and this is what would have happened when I clicked the OK button, in the same window, the previous question was replaced with the next question and the following 4 possible answers.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

  1. You place a text field or a JLabel with a question and a group of radio buttons with options for answers. They all have the Text property (you can set it via setText or setLabel ).

setText (String text) This component will display.

https://docs.oracle.com/javase/8/docs/api/javax/swing/JLabel.html

The same method (setText (String text)) for JRadiobutton: https://docs.oracle.com/javase/8/docs/api/javax/swing/JRadioButton.html

  1. After the user makes a choice of a radio button, the property will change to selected = true . ( setSelected() we call ourselves at the event of pressing the radio button.)

There is a detailed manual for each type of control (buttons of different types, including radio buttons).

  1. By clicking on the OK button, your task is to read which radio button isSelected or selected/checked == true .
  2. After accepting the answer, assign new texts to their label/text properties. If there are many or few radio buttons, add new ones to the form or hide (or remove, but better hide).
  3. Repeat until the test questions run out.

JRadioButton : https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/components/RadioButtonDemoProject/src/components/ RadioButtonDemo.java

A simpler example: http://www.codejava.net/java-se/swing/jradiobutton-basic-tutorial-and-examples