Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java屏幕如何使输入行始终位于下方_Java - Fatal编程技术网

Java屏幕如何使输入行始终位于下方

Java屏幕如何使输入行始终位于下方,java,Java,我的问题是: 当我扫描此方法中的用户输入时 public static void listenForCommand() { @SuppressWarnings("resource") final Scanner s = new Scanner(System.in); System.out.print(">"); final String line = s.nextLine(); String[] args = new String[line.spl

我的问题是: 当我扫描此方法中的用户输入时

public static void listenForCommand() {
    @SuppressWarnings("resource")
    final Scanner s = new Scanner(System.in);
    System.out.print(">");
    final String line = s.nextLine();

    String[] args = new String[line.split(" ").length-1];
    for (int i = 1; i < line.split(" ").length; i++)
        args[i-1] = line.split(" ")[i];

    commandEntered(line.split(" ")[0], args);
}
publicstaticvoid-listenForCommand(){
@抑制警告(“资源”)
最终扫描仪s=新扫描仪(System.in);
系统输出打印(“>”);
最后一行字符串=s.nextLine();
String[]args=新字符串[line.split(“”.length-1];
对于(int i=1;i
然后是“>” 但是如果某个东西被打印或记录,那么它看起来是这样的 (我不能使用图像格式,因为它说:“你需要至少10个声誉来发布图像。”而我没有10个声誉。)

那么我该如何解决这个问题呢?是否有一些API或库用于此?我想让它看起来像是龙头或是傻瓜

我的命令侦听器类: 当控制台获得输入时,它会将第一个单词分割到命令中,其他所有内容都是args。然后,如果有使用输入的commandname注册的命令,它会询问main中每个注册的命令

package at.gebes.utils.command;

import java.util.Scanner;

import at.gebes.bot.Bot;

public final class CommandListener {

public static String[] commandNames = new String[1000];
public static String[] commandDescriptions = new String[1000];
private static CommandExecutor[] CommandClasses = new CommandExecutor[1000];
public static int counter = -1;

public static void registerCommand(final String CommandName, final String CommandDescription, final CommandExecutor CommandClass) {

    counter++;
    commandNames[counter] = (CommandName);
    commandDescriptions[counter] = (CommandDescription);
    CommandClasses[counter] = CommandClass;

}

public static void listenForCommand() {
    @SuppressWarnings("resource")
    final Scanner s = new Scanner(System.in);
    System.out.print(">\n");
    final String line = s.nextLine();
    //final String line = System.console().readLine();

    String[] args = new String[line.split(" ").length-1];
    for (int i = 1; i < line.split(" ").length; i++)
        args[i-1] = line.split(" ")[i];

    commandEntered(line.split(" ")[0], args);
}

public static void commandEntered(final String cmd, final String[] args) {

    if (counter < 0) {
        return;
    }

    boolean commandExists = false;
    try {

        for (int i = 0; i <= counter; i++) {

            if (commandNames[i].equalsIgnoreCase(cmd)) {
                CommandClasses[i].onCommand(commandNames[i], args);
                commandExists = true;
                break;
            }
        }

    } catch (final NullPointerException e) {
        e.printStackTrace();
    }

    if (!commandExists) {
        Bot.getLogger().info("Unknown Command. Try \"help\" for a list of commands.");
    }
}
package at.gebes.utils.command;
导入java.util.Scanner;
在.gebes.bot.bot导入;
公共最终类CommandListener{
公共静态字符串[]commandNames=新字符串[1000];
公共静态字符串[]commandDescriptions=新字符串[1000];
私有静态CommandExecutor[]CommandClasses=新CommandExecutor[1000];
公共静态int计数器=-1;
公共静态无效注册表命令(最终字符串CommandName、最终字符串CommandDescription、最终CommandExecutor CommandClass){
计数器++;
命令名[计数器]=(命令名);
commandDescriptions[计数器]=(CommandDescription);
CommandClass[计数器]=CommandClass;
}
公共静态void listenForCommand(){
@抑制警告(“资源”)
最终扫描仪s=新扫描仪(System.in);
系统输出打印(“>\n”);
最后一行字符串=s.nextLine();
//最后一行字符串=System.console().readLine();
String[]args=新字符串[line.split(“”.length-1];
对于(int i=1;i对于(int i=0;i在这种情况下,您必须在任何
字符串
类型变量中记录当前屏幕,然后每次用户输入时必须清除屏幕,然后显示记录的屏幕,然后显示输入行


我想你明白我的意思了。

什么是输入的
命令
,你在哪里打印
帮助
或任何非
的东西?请将更改
系统输出打印(“>”);
发布到这个
系统输出打印(“>”)中
我试过了,但是:1.行号并不总是在2以下。如果一条消息或异常在一段时间后被打印出来,它仍然看起来像this@Gebes,然后在打印的消息之后添加
\n
,那么问题就解决了。我只希望输入行始终是最下面的行。如果打印了新的内容,它应该在输入端line@Gebes,在这种情况下,您必须在字符串变量中记录当前屏幕,然后每次用户输入时清除屏幕,然后显示记录的屏幕,然后显示输入行……我想您明白我的意思了