Jump to content
  • Advertisement
Sign in to follow this  
World69star

[java] Console and Gui User Input... How??

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I have a few months of java programming behind me and would like to start the first part in an Rpg that has been swirling in my mind for years. ...Back in the stone age of PC's is when I got my first taste in programming..the language was Basic(Gw, later Q). I tried making an Rpg with that back then in high school in the late 80's with a cga display and no internet well it didn't turn out that well. But I did make a very impressive(to me at least) 1st Edition AD & D CHaracter maker + random Generator option with print capabilities. It was simple to make back then. So now I want to use a modified version of that for an Rpg player Character segment, which I think will be a good goal for my first "large" project. Instead of Printing the answers on paper, I just need the ability to store the user inputed text or numbers in corresponding Strings or Int's respectivly. Back then I could usse the simple input command: 10 Print "What is your name?" 20 Input "name", name 30 Print name //Something like that it's been 15 years since my last spree in programming so the syntax mite be wrong but you should get the idea. .....Fast Forward to 2005 and my learning of Java after a few months of and 3 books later I cannot for the life of me find an equivalent of the input function from basic, and I need this to make the character generator for the console at least and then to a gui when I'm ready. For now I would just like to port my old program. ....Sorry to rant.. So here is my questions... 1.) What Java Classes in the languge contain what I need for input and jow would I use it? (To retreave input and then to store it in an associated variable to it's kind(Int/String/Boolen etc..)) 2.) If there is no simple class for it would somebody be able to give me a user wriiten class/or method I could use for input and storing to use in my program. Thank you in advanced you guys have helped me out before and I plan on helping more people out here once my knowlege of Java is more grounded. So thanks anyone who replays! -Later, Rob.

Share this post


Link to post
Share on other sites
Advertisement
Also what I am talking abour is actuall user input whille the program is running not commandline arguments (or html arguments) that you supply before the program runs. I know how to do those. All the books taught me that and hardlineing variable but no user input:(

Share this post


Link to post
Share on other sites
Try this to read a String in from the console:

public String readString() {
InputStreamReader stdin = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(stdin);
String input = "";
try {
input = console.readLine();
} catch(Exception ex) { }

return input;

}



You can use it as follows:

String myString = readString();

The program would pause and wait for the user to enter a String in the console. You can change it easily to read specific things like ints and chars if you like. hope this helps a bit :)

Share this post


Link to post
Share on other sites
Hey Deobotha, Thank you so much! That is exactly what I was looking for! Do you think this would work in a Awt/Swing gui app instead of a console? (That is my step after I create the console version.) Or do I need to use something else? Thanks again.

Share this post


Link to post
Share on other sites
All this stuff is fully explained for free in Sun's official Java Tutorials. They're good, very good. You should work through them (only takes an hour or two to do a complete set on any particular topic, or much less if you're a fast learner).

Googllin "java sun tutorial":

http://java.sun.com/docs/books/tutorial/

Especially, for you:

http://java.sun.com/docs/books/tutorial/uiswing/index.html

Which you should really work through the whole of, even though there's a lot. Part way through you'll discover how to make graphical text widgets and how to get input from them, and you'll learn about M/V/C which makes your life SO much easier when your RPG starts to get lots of buttons, textfields, etc that it's worth learning from the start.

redmilamber

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!