我正在创建一个基于文本的程序/游戏,我认识的人创建了一个将控制台打开到Windows命令提示符的程序。这使它可以不断刷新,使文本清晰,外观整洁,而不是笨重的控制台视图,只是将文本添加到其上,为基于文本的游戏制作了不良媒体。
答案 0 :(得分:0)
以下可能会给你一个想法:
public static void main(String[] args) throws Exception {
// Since you are using eclipse, bin contains the compiled classes
// This depends on your working directory.
File directory = new File("bin");
// In my case, the main class is Game (in the default package)
ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "java", "Game");
// directory defined above
pb.directory(directory);
// The fun begins!
pb.start();
}
Game
类仅包含以下内容:
import java.util.Scanner;
public class Game {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
System.out.println(sc.nextLine());
}
}
}