• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

JTextField/JTextArea

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic