Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with Random number generator

 
Mike Suh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike Suh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Mani!
 
Igor Ko
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic