lundi 27 janvier 2020

JTextField Update Text

I am using Java8 Swing. I have 2 JTextfields, one of which has a user input and the other that I want to display random numbers (btwn 1-100) until it matches the user input. I know the new random numbers are being generated becuase I see them when they are being printed out. However, my textfield is not showing any of the updated numbers and just shows the final random number that eventually matches the user input number. What am i doing wrong?

setButton.addActionListener(new ActionListener() {
     @Override
     public void actionPerformed(ActionEvent e) {
        double setCrystalTemp = Double.parseDouble(crystalSetTF.getText());
        Random random = new Random();
        int crystalTempRandom = 0;
        while (crystalTempRandom != setCrystalTemp) {
           random = new Random();
           crystalTempRandom = random.nextInt(100);
           crystalTempTF.setText(String.valueOf(crystalTempRandom));
           System.out.println(crystalTempRandom);
         }
     }
});



Aucun commentaire:

Enregistrer un commentaire