現在、implements runnable
というクラスを実行するプログラムを作成中です。 私はHH:MM:SS
という形式の時刻が毎秒画面に表示されるようにしています。 HERESにコード:ここ時計システムのコンソールを消去する方法
public class LaunchCounter
{
public static void main(String[] args)
{
//Runs the CounterThread
new CounterThread().start();
}
}
そして、これは完全に正常に動作カウンタクラス
public class CounterThread implements Runnable
{
//Declare new thread
private Thread thread;
public void start()
{
thread = new Thread(this, "");
thread.start();
}
@Override
public void run()
{
//Formatter used to display just time not date
DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
//never ending forloop to display time
for(int i = 1; i > 0; i++)
{
try
{
//Runtime.getRuntime().exec("cmd /c cls");
//Sleep for 1 second after each loop
Thread.sleep(1000);
//new calender is created
Calendar cal = Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));
}
catch(Exception e1)
{
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
です。 私が達成しようとしているのは、印刷された行が1秒待ってから消去され、新しい時刻が印刷されるなどです。 従って12:00:01
ベクトコム12:00:02
アウトが新しい行をとっています。
私は試しましたSystem.out.print("\b\b\b\b\b\b\b")
とRuntime.getRuntime().exec("cmd /c cls");
これは、正方形をコンソールに印刷しているだけです。
どうすればいいですか?
私はJavaで、「コンソール」は、画面上のウィンドウではないこと、のnoobの利益のために、追加しますhttps://github.com/fusesource/jansi – rkosegi