문제

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