wood burning stoves 2.0*
The moose likes Java in General and the fly likes Help with Random number generator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help with Random number generator" Watch "Help with Random number generator" New topic
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 ]
 
Don't get me started about those stupid light bulbs.
 
subject: Help with Random number generator
 
Similar Threads
Class Random or Math.random()???
lock and unlock
Minimum and maximum random number?
how to generate random numbers ? Random class always generate same number....
Variables assigned to objects