mardi 12 septembre 2017

Random number in text field

I have JUST started with Java and i just want to make a little program, a little game based on luck, where i have to guess a randomly chosen number and whenever i guess it, a window pops up giving me a message.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String haha = jTextField1.getText();
   Random celka = new Random();
   int ciprx = celka.nextInt(6)+1;

   if (haha.contains(ciprx)){
       JOptionPane.showMessageDialog(null, "BUHĀ!");
   }
}   

The problem is that i cant write ciprx after .contains, since that is and integer and i cannot put that there, but i need the text field to contain the (secretly) randomly generated number in case to show me the pop-up message. Its fine, however, if i just put an "a" after the .contains, for example. How can i fix this?




Aucun commentaire:

Enregistrer un commentaire