Results 1 to 3 of 3
  1. #1
    Razion is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default equivalent for JTextArea

    Hello, all!

    I'm attempting to create a text-based RPG that displays in a swing window using a JTextArea for output and a JTextBox for input.

    Without the GUI elements, I've made a similar project that functions well. The problem comes with trying to get input. In a console, I can force a pause to wait for input using, however I'm not sure how to cause a similar event using a JTextBox. Is it possible to use a scanner for this purpose? If not, what else could I do? Any ideas would be greatly appreciated.


  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default Re: equivalent for JTextArea

    In a GUI you typically don't wait for user input: instead you respond to input when it happens. If you're unfamiliar with the approach it would be worth while stepping back from the program you want to write and having a look at a basic Swing tutorial. (Knowledge of how to write modest GUI applications should inform your design rather than letting it be driven by fixed ideas developed in another context).


    That said your JTextField could form the basis for a scanner. One way would be to note that a Scanner can be constructed from (ie "wrap") any Readable or InputStream source. So one could try implementing Readable or extending InputStream in such a way that the data comes from the JTextField.

    Such an approach is *not* trivial and will require some familiarity with both Swing and working with threads. So you are driven back to understanding Swing and, from that perspective, it makes more sense to write a "standard" GUI where text entered in the text box "triggers" subsequent actions (update of the state of the game, and output to the text area).
    Last edited by pbrockway2; 06-07-2012 at 10:17 AM. Reason: see following...

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: equivalent for JTextArea

    Quote Originally Posted by Razion View Post
    I'm attempting to create a text-based RPG that displays in a swing window using a JTextArea for output and a JTextBox for input.
    What's a JTextBox? No such class in the standard JDK.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. What is equivalent for loop?
    By diamonddragon in forum New To Java
    Replies: 5
    Last Post: 01-15-2012, 10:16 AM
  2. HQL equivalent to this Sql Query
    By shomid in forum Advanced Java
    Replies: 0
    Last Post: 10-27-2011, 09:43 AM
  3. JTextArea on PopUp -JTextArea isn't editable
    By Richy76 in forum AWT / Swing
    Replies: 3
    Last Post: 02-01-2010, 08:51 PM
  4. VB Net FIX equivalent?
    By bullstreetboy in forum New To Java
    Replies: 3
    Last Post: 04-06-2009, 06:31 PM
  5. Replies: 1
    Last Post: 11-21-2007, 01:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts