Recently I have been making a little java game where you build up a city and have to defend it. Now I want to make it ready for proper testing. I was thinking of having the server running on an old computer of mine, than I would have to make it so that, while the program is running, I can type in commands that will be executed. Like the minecraft or craftbukkit servers have. There you can type in text and press enter in the same console as where you started the program. Anybody got any ideas?
1 Answer
Sounds like you just need a Scanner object.
For example, to continuously wait for input and then print that input, you would write:
Scanner s = new Scanner(System.in);
String foo = s.nextLine();
System.out.println(foo);
System.in as the constructor parameter specifies that you are reading input from the keyboard (as opposed to a file, for example).