javaoutputnetbeans-6.9

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


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

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.

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

cannot find symbol symbol: class AWTException

cannot find symbol symbol: variable Logger

cannot find symbol symbol: class 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

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

cannot find symbol symbol: class LoginPage location: class 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

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.


Solution

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

    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);
    }