Frage

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("################");
War es hilfreich?

Lösung

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

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top