printing - Print string to a java.io.Console object -
i'm making multi-player game each player has own input/output console on screen. i'm having bit of trouble trying this. don't want every player see other player's in/outputs.
to use analogy, want playeroneconsole.out.println("player 1 string");
, instead of system.out.println("player 1 string");
can see player one's stuff.
after reading documentation, i've tried this, not work intended throws nullpointerexception:
public class player { string myname; console myconsole; public player(string name) { myname = name; myconsole = system.console(); } public void taketurn(string playeroptions){ myconsole.writer().print(playeroptions); //this not right. } }
i want playeroptions
print exclusively player's console, not system
console.
by way, i'm using netbeans ide 8.0.2 if makes difference.
when using java.io.console
, must execute java app console e.g. windows cmd or linux terminal. ides won't execute java through console, system#console
returns null
.
by way, code:
myconsole.writer().print(playeroptions); //this not right.
it's right indeed :)
Comments
Post a Comment