質問

i want to create a terminal application in java, but i don't know how to replace text lines that are already printed (kind of "edit the lines that already printed"). \r only returns to the beginning of the last line, and i want to display a 2 dimensional grid. this is a sample for what i want to print:

System.out.println("################");
System.out.println("#--------------#");
System.out.println("#--------------#");
System.out.println("################");


System.out.println("\r################");
System.out.println("#-------X------#");
System.out.println("#--------------#");
System.out.println("################");
役に立ちましたか?

解決

you should try JLine library. It provides many userful functions for command line applications. http://jline.sourceforge.net/javadoc/

他のヒント

Using System.out.println whatever text is printed to the console is already flushed and cannot be edited. What you can do is you can clear the console and reprint using a fresh set Sys Outs. But for a graphical application I would suggest you have a look at JAVA AWT which will give you functions like paint() and repaint() and other rich UI functions.

For clearing the console you can refer to this: clear console

For JAVA AWT: AWT tutorial

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top