| Author |
Help with Random number generator
|
Mike Suh
Greenhorn
Joined: Jan 12, 2004
Posts: 2
|
|
Sorry, this is a newbie question, but I dont think anyone in the beginners section knows the answer to this. This is the code that I wrote, but I get a "Variable setText not found in class javax.swing.JTextField" error. I just want to know how to make a simple random number generating program. Heres the code: private void pickRandomNumber() { Random randomObject = new Random(); int number = 1 + randomObject.nextInt(6); jTextField.setText = String.valueOf( number ) ; }
|
 |
Mani Ram
Ranch Hand
Joined: Mar 11, 2002
Posts: 1140
|
|
To set a value to the JTextField you should use the setText() method. Here you are using setText as if it is a variable. Try this code
|
Mani
Quaerendo Invenietis
|
 |
Mike Suh
Greenhorn
Joined: Jan 12, 2004
Posts: 2
|
|
|
Thanks alot Mani!
|
 |
Igor Ko
Ranch Hand
Joined: Jun 24, 2002
Posts: 90
|
|
You should create random generator only ONE time, not each time when you get the next random number. [ January 15, 2004: Message edited by: Igor Ko ]
|
 |
 |
|
|
subject: Help with Random number generator
|
|
|