Java gotoxy(x,y) for console applications

给你一囗甜甜゛ 提交于 2019-11-26 02:57:09

问题


I\'m writing a simple console application (80x24) in Java, is there a gotoxy(x,y) equivalent?


回答1:


If by gotoxy(x,y), you want to reposition your cursor somewhere specific on the console, you can usually use VT100 control codes to do this. See http://www.termsys.demon.co.uk/vtansi.htm.

Do something like

char escCode = 0x1B;
int row = 10; int column = 10;
System.out.print(String.format("%c[%d;%df",escCode,row,column));

Which should move the cursor to position 10,10 on the console.




回答2:


I don't think there's a built-in function to do that in Java. There's a Java curses library called JCurses that you can use though.




回答3:


Not without pulling in a console curses style library...

You can try javacurses and see if that helps you.




回答4:


I found lanterna to be a very good library. It does not dependend on any native library but runs 100% in pure Java.

It offers a Screen class which allows text output based on a coordinate system. For OS with a graphical environment it uses a Swing based terminal emulator. Unfortunately, you are not able to force terminal mode on Windows, so if you really need the terminal, use one of the solutions in the other answers.



来源:https://stackoverflow.com/questions/1001335/java-gotoxyx-y-for-console-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!