Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java GUI: comparing JTextField values  RSS feed

 
enombe thierry
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i have an int guess = 1 + randomNumbers(1000)

I want to compare an integer which is inserted in a JtextField with a randomly generated integer.I don't know which method to use so i can compare the inputted int with the random number.At first i thought it is "event.getActioncommand" but i later realizes that it was a method that returned a string.

How do i equate guess to an int value inserted in a JtextField
 
K. Tsang
Bartender
Posts: 3620
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you written code to generate the random number? You know this generated number is a double right?

Do you know how to get the value of the JTextField? This value is a string even if you enter digits.

Do you need to do the checking on the fly immediately when the cursor looses focus or when the submit button is clicked?
 
enombe thierry
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K. Tsang wrote:Have you written code to generate the random number? You know this generated number is a double right?

Do you know how to get the value of the JTextField? This value is a string even if you enter digits.

Do you need to do the checking on the fly immediately when the cursor looses focus or when the submit button is clicked?


yea i do need to click a button
 
K. Tsang
Bartender
Posts: 3620
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make 2 JTextFields and a JButton. Attach an action listener to the JButton. In the action listener's actionPerformed() method, get the the JTextField values and compare.

Make sure the 2 JTextFields are accessible from the action listener (eg not a local variable).

This should get you started. You can refer to the Swing tutorial for setting up you GUI.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!