Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

pythonfan

[java] application question

This topic is 5655 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

I was thinking of doing a text adventure game in java(as an application); but I can''t for the life of me find, anywhere, information on reading text from a prompt. I just can''t find anything;I''ve checked all the books I have, and the java documentation. Might someone be able to enlighted me?

Share this post


Link to post
Share on other sites
Advertisement
Well,

IMHO writing a simple GUI application (one window with a text area and an input field) would do the trick. Unless, of course, your target machine is a text only terminal.

have fun

Petr Stedry

edit: replaced "linux console" with "text only"

[edited by - Petr Stedry on January 28, 2003 6:29:58 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Petr Stedry
Well,

IMHO writing a simple GUI application (one window with a text area and an input field) would do the trick. Unless, of course, your target machine is a linux console terminal.

have fun

Petr Stedry



Hey, what''s that supposed to mean? We get GUIs in Linux too you know As an aside, Windows has a console. So does Mac OS X. Why pick on Linux?

Share this post


Link to post
Share on other sites
Whoa ...
this was not intentional!

I myself am using linux to develop java games (gone the linux way since early 2002).

So there''s no need to flame me to the bone

The only possible reason, that I described a "text only terminal" as a "linux console terminal" is possibly my personal experience from times long gone.

I will edit my previous post to correct this, thanks for mentioning NuffSaid.




Petr Stedry

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
linux sucks

Share this post


Link to post
Share on other sites
Linux is the choice OS if you want rock solid stability while you edit that ascii text file.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
linux sucks


Holy shit, your insight is enourmous.

Than you for your contribution to our evergrowing community.

Share this post


Link to post
Share on other sites
I think what he's looking for is completely text-based.
In this case, instead of creating a basic GUI for reading input you can use a BufferedReader... follow carefully.

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

You see, the BufferedReader class "wraps around" a Reader, and InputStreamReader IS-A Reader. The InputStreamReader needs an input stream to read, and System.in is connect to standard input by default.

Then...
String input = stdin.readLine();

Of course, you'll want to read in other types, in which case you'll need the wrapper classes (Integer class, Double class, etc), particularly their parsing methods.

Example: Integer.parseInt(input);

But that's nonsense, you say, because the user doesn't have to enter a number! Well, in this case, if input is not a number a NumberFormatException will be thrown. =)

Hopefully I haven't made any really stupid errors.
EDIT: AHHH!!! I missed some important details!
1) You must import the java.io package (import java.io.*
2) You must be prepared to throw/catch IOException because it is a checked exception that may be thrown! I'm not sure as to the BEST way of handling this. Any comments?

This isn''t life in the fast lane, it''s life in the oncoming traffic.
-- Terry Pratchett

[edited by - Kentaro on January 28, 2003 5:02:57 PM]

Share this post


Link to post
Share on other sites
to quote Mel Brooks'' masterpiece, "The Pruducers":
"Dankeschon baby!"

Thanks a lot when I get my TAS to a playable stage, I''ll be sure to post for evaluation. Thanks again.

Share this post


Link to post
Share on other sites

  • 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!