• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextField/JTextArea  RSS feed

 
Shonen Jump
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a quiz in a Swing. I have a JTextField called inputField and a JTextArea called text. When I type something in inputField and click on a button called Enter, the text is displayed on the text area.

So far in the textarea, the first question is displayed. I can type the answer in the inputField and submit it. Problem is it doesn't tell me if it is correct and I'm not sure how to do an if statement with JTextArea/JTextField.

The part of the code with the problem:
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand your question, it seem like all you need to do is to
check the contents of inputField, not text.

Maybe something like this:
 
Shonen Jump
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks that worked!

If I put it in a loop, how can I have it so it waits for user input? Because it just keeps repeating the question without waiting for my input.
[ October 12, 2004: Message edited by: Shonen Jump ]
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not exactly sure what you're after here.

I thought you said that these text operations took place after a button was pressed.

Are you getting your input from a text field or from the keyboard?
 
Shonen Jump
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
um well let me put it this way. Lets say now I have a computer player. We each get a chance to answer a question, but it only allows the computer to do so and not wait for my answer, then moves on to the next question and not wait for my input again and again until the game is over and the computer wins. How can I make it so it waits for my input from the textfield before moving on?
[ October 13, 2004: Message edited by: Shonen Jump ]
 
jefff willis
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems fairly simple (although the requirements sound stange).

Have the application accept input from the computer, then check to see if there is input from the user. If so, update the TextField, if not, don't.
 
Shonen Jump
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After my first input, it uses that input for the answer of each of the questions. It won't let me input something new. How can I update the textfield?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!