I am creating a small application in java that calculates bets automatically. When clicking on the results button, a JDialog is automatically created that shows on a TextArea the bet that has been created automatically and another that is also created automatically and makes the winner. In the same interface of the program there is a statistical button that when clicking, 1000 bets are generated automatically and compared with a winner also generated in a random way. I have the problem, in which I use the JDialog for both, and if I create a statistic before clicking on the results button, it shows me the 1000 results (up to that point). But if after I click on results, the same JDialog reopens with those results. And what I intend is that even if it is the same JDialog, it is cleaned for each action. attached code so far from the acctionListener
resultadosBt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(resultadosBt.getText() == "Resultados"){
resultados = new Resultados(apuestas, apuesta, "Resultados", ventana);
}
}
});
estadisticaBt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(estadisticaBt.getText() == "Estadistica"){
contador = 0;
while(contador < 1000){
generaApuestaAutomatica();
contador++;
}
resultados = new Resultados(apuestas, apuesta, "Estadistica", ventana);
}
}
});
This is the interface, so you can get an idea:
When I click on statistics, the 1000 bets are created and compared with a winner and everything is shown in a JDialog:
When I click on results it should appear empty unless I give the automatic button, which then stores the bets and shows them in results.