jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help with Random number generator" Watch "Help with Random number generator" New topic

Help with Random number generator

Mike Suh

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

Quaerendo Invenietis
Mike Suh

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 ]
I agree. Here's the link: http://aspose.com/file-tools
subject: Help with Random number generator
It's not a secret anymore!