My code looks like this:
public class QuestionarioController implements Initializable {
InicioController inicio = new InicioController();
Quiz questionario = new Quiz();
@FXML
private Label lblPergunta;
@FXML
private RadioButton rbQuestion1;
@FXML
private RadioButton rbQuestion2;
@FXML
private RadioButton rbQuestion3;
@FXML
private RadioButton rbQuestion4;
@FXML
private Button btnavancar;
@FXML
private void handleAvancar(ActionEvent event) throws IOException {
inicio.handleIniciar(event);
}
@Override
public void initialize(URL url, ResourceBundle rb) {
try {
carregaInfo();
} catch (ClassNotFoundException ex) {
Logger.getLogger(QuestionarioController.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(QuestionarioController.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void carregaInfo() throws ClassNotFoundException, SQLException {
MyConnection myConnection = new MyConnection();
myConnection.statement = myConnection.connection.createStatement();
Random gerador = new Random();
int numeroGerado = gerador.nextInt(4);
if (questionario.getNumeros().contains(numeroGerado)) {
numeroGerado = gerador.nextInt(4);
} else {
questionario.setNumeros(numeroGerado);
}
String sql = "SELECT * FROM question WHERE cod_question = " + numeroGerado;
myConnection.result = myConnection.statement.executeQuery(sql);
while (myConnection.result.next()) {
questionario.setDescription(myConnection.result.getString(2));
questionario.setQuestion1(myConnection.result.getString(3));
questionario.setQuestion2(myConnection.result.getString(4));
questionario.setQuestion3(myConnection.result.getString(5));
questionario.setQuestion4(myConnection.result.getString(6));
//correct = myConnection.result.getString(7);
}
this.lblPergunta.setText(questionario.getDescription());
this.rbQuestion1.setText(questionario.getQuestion1());
this.rbQuestion2.setText(questionario.getQuestion2());
this.rbQuestion3.setText(questionario.getQuestion3());
this.rbQuestion4.setText(questionario.getQuestion4());
}
}
The goal is that when I click Next, the same screen appears, only with different questions. So far so good, but I do not want you to repeat questions. I am trying to save the generated numbers in an ArrayList to go checking if a number has already left or not. However, it is not adding the elements to the list, it is starting a new one every time it calls the method.
Instead of [1] [2] [3] it is:
Home
[1]
[2]
[3]
In the Quiz class (where ArrayList
is) it looks like this:
public class Quiz {
private String description;
private String question1;
private String question2;
private String question3;
private String question4;
private String correct;
private int qtdAcerto;
private boolean controle = false;
ArrayList<Integer> numeros = new ArrayList();
public ArrayList<Integer> getNumeros() {
return numeros;
}
public void setNumeros(Integer numeros) {
this.numeros.add(numeros);
}
}
Other getters and setters were hidden.
I have tried to leave the list in this same control class, and it worked anyway. I can not find the problem in any way = (