我想使用 NetBeans IDE 6.9.1 清除 Java 中的输出屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16067358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 21:47:26  来源:igfitidea点击:

I want to clear my output screen in Java using NetBeans IDE 6.9.1

javaoutputclearnetbeans-6.9

提问by Brandon Durst

My entire code can be found at the link below, I'm linking it for the sake of a shorter post

我的整个代码可以在下面的链接中找到,我链接它是为了更短的帖子

http://pastebin.com/6kw8cx3b

http://pastebin.com/6kw8cx3b

I want to clear the Output screen, I'm to make the program simulate a user pressing ctrl+L, which in NetBeans IDE 6.9.1 (which I'm using) clears my output window. However, I'm getting errors with my code.

我想清除输出屏幕,我要让程序模拟用户按下 ctrl+L,这在 NetBeans IDE 6.9.1(我正在使用)中清除我的输出窗口。但是,我的代码出现错误。

public static void clearme()
{
    try
    {
        botthing pressbot = new botthing();
        pressbot.keyPress(17); // Holds CTRL key.
        pressbot.keyPress(76); // Holds L key.
        pressbot.keyRelease(17); // Releases CTRL key.
        pressbot.keyRelease(76); // Releases L key.
    }
    catch (AWTException ex)
    {
        Logger.getLogger(LoginPage.class.getName()).log(Level.SEVERE, null, ex);
    }
}

My errors were...

我的错误是...

Cannot find symbol symbol: class botthing

找不到符号符号:类botthing

cannot find symbol symbol: class AWTException

找不到符号符号:类 AWTException

cannot find symbol symbol: variable Logger

找不到符号符号:变量记录器

cannot find symbol symbol: class LoginPage

找不到符号符号:类 LoginPage

cannot find symbol symbol: variable Level

找不到符号符号:变量级别

HOWEVER!After adding these import statements

然而!添加这些导入语句后

import java.awt.AWTException;
import java.util.*;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

my errors are...

我的错误是...

cannot find symbol symbol: class botthing location: class program2

找不到符号符号:类botthing位置:类program2

exception java.awt.AWTException is never thrown in body of corresponding try statement

异常 java.awt.AWTException 永远不会在相应的 try 语句的主体中抛出

cannot find symbol symbol: class LoginPage location: class program2

找不到符号符号:类 LoginPage 位置:类 program2

I'm not sure what those mean, but I think the java.awt error could be related to my main(), which is public static void main(String[] args) throws IOException

我不确定这些是什么意思,但我认为 java.awt 错误可能与我的 main() 有关,它是 public static void main(String[] args) throws IOException

All I want to do is clear my output screen. I've also tried

我想要做的就是清除我的输出屏幕。我也试过

for(int x=0;x<999;x++)
{
    System.out.print("\b\b\b\b\b");
}

and

Runtime.getRuntime().exec("cls");

but both to no avail.

但两者都无济于事。

If the code I've been trying can't be easily fixed, or if someone knows an easier way, I'd love to know. To clarify, all I want to do is clear my Output window after multiple System.out.println's and such.

如果我一直在尝试的代码无法轻松修复,或者有人知道更简单的方法,我很想知道。澄清一下,我想要做的就是在多个 System.out.println 等之后清除我的输出窗口。

回答by BackSlash

botthing is not something defined in the JDK, and if it is a class that you defined, your compiler is not finding it.

botthing 不是 JDK 中定义的东西,如果它是您定义的类,则您的编译器找不到它。

Try using:

尝试使用:

try {
    Robot pressbot = new Robot();
    pressbot.keyPress(17); // Holds CTRL key.
    pressbot.keyPress(76); // Holds L key.
    pressbot.keyRelease(17); // Releases CTRL key.
    pressbot.keyRelease(76); // Releases L key.
} catch (AWTException ex) {
    Logger.getLogger(LoginPage.class.getName()).log(Level.SEVERE, null, ex);
}