Results 1 to 9 of 9
  1. #1
    gundum584 is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default [help] Java text reader

    Well im currently working on a game and I cant figure out how to make it constantly look for text.

    Im trying to make it so a user can press a button and it will do stuff instead of having to have a readln to see if the user pressed the button it will allready be looking for user input. Like in maplestory,runescape,wow ect... you can always insert text and when you inseret a certain thing like @help it dose something different. So how would i go about making a method or class that will constantly look for user input while still being able to run the main program?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default

    Is this a GUI program or commandline? Much easier to do if your have text fields for user input.
    With text fields, instead of constantly looking for input, your program uses listeners. Then when the text field changes your code is called.

    From the details of your post, this may be too advanced.
    Perhaps if you explain a bit more about how the app is suposed to work.

  3. #3
    gundum584 is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    its command line. I have like preset commands with it like if the user enters w it will do this or if they press h it will do this ect.. but i dont know how to make it automatically register it when they press it. Right now i have to ask them to enter the letter then have a readline to see if they pressed it. Is there any way to do what im trying to w/o having a gui text feild?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default

    what im trying to
    I'm not sure exactly what it is you are trying to do.
    Without a GUI, you have to ask the user for input, read the input, do something, then go back and do it again.
    How is what you want to do different than this approach?

    With GUI there is code that is part of the JRE that can react when the user has pressed a key and tell the program about it. This can be done with listeners.

  5. #5
    gundum584 is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    so the only way i can do what i want is with a gui?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default

    Can you explain what do you want again?
    if the user enters w it will do this or if they press h it will do this
    That could describe reading input from the commandline.
    how to make it automatically register it when they press it
    What does "register it" mean here?
    make it constantly look for text.
    What is the program going to be doing while it is waiting for text to be entered? Animation?

  7. #7
    gundum584 is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    There is no visuals in the game it is only text. its like civilization or dwarf fortress w/o visuals
    so while the program is waiting for text input it will be telling whats going on. Like it will be saying "the river is about to flood" in which case you would want to press w to make a worker. but the way i have it set up right now after i say the river is about to flood i would have to have an input to check if the user pressed w to make a worker. What i want is so i dont have to check if the user pressed a button. I want it to automatically check. and by automatically i mean it dosnt just check if the user pressed w so say the user wanted to save insted of build a worker he/she would press "s" but it would be looking for "w" and not "s" i need something that would look for all my commands.

  8. #8
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    304
    Rep Power
    6

    Default

    You could try reading the input in another thread, however I don't think input is registered until enter is hit.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,586
    Rep Power
    23

    Default

    I don't think there is a way with a command prompt program to be outputting text while waiting for the user to input text. You'll have to use a GUI to be able to do that.

Similar Threads

  1. RSS Reader
    By dage_001 in forum Networking
    Replies: 16
    Last Post: 04-25-2010, 01:41 PM
  2. Replies: 4
    Last Post: 04-23-2010, 01:54 PM
  3. help with input reader
    By masterhoulahan in forum New To Java
    Replies: 2
    Last Post: 03-25-2009, 05:12 AM
  4. Java file reader...?
    By prabhurangan in forum New To Java
    Replies: 3
    Last Post: 11-21-2008, 08:19 AM
  5. Maze reader
    By bix in forum New To Java
    Replies: 1
    Last Post: 11-20-2008, 06:06 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
  •