Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java gotoxy(x,y) for console applications

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

like image 914
setzamora Avatar asked Jun 16 '09 13:06

setzamora


People also ask

What is gotoXY in java?

public void putString(java.lang.String s) Places a String on the screen starting at the current screen cursor location. To place a string at a specific location use the gotoXY() method to set the cursor, or use the putStringAt() method.

How do I clear the java console?

To clear the console in Java, we will use the escape code \033[H\033[2J . This weird set of characters represents the command to clean the console.


1 Answers

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.

like image 86
Tom Jefferys Avatar answered Sep 25 '22 13:09

Tom Jefferys