Search code examples
javaappletstatus

How to clear the status text of a Java applet?


I am programming the game Breakout in Java using an applet and I used some showStatus("") lines to say someting in the window of the applet.

But when I start a new game, I want that the status text disappears. That is, when a key is pressed and some action happens. If the up arrow (key 1004) is pressed, the game starts and I want the status text gone.

How can I achieve this?

This is my solution so far:

public boolean keyDown(Event e, int key) {
    if(key==1004 && ballready) {
        ballready = false;
        ball.xchange = BallSpeedX;
        ball.ychange = BallSpeedY;
    }
    if(key==1006)
        leftArrow = true;
    if(key==1007)
        rightArrow = true;
    return true;
}

Solution

  • The answer is very simple! Just by adding literally the showStatus(" ").

      public boolean keyDown(Event e, int key) {
        if(key==1004 && ballready) {
            ballready = false;
            ball.xchange = BallSpeedX;
            ball.ychange = BallSpeedY;
            showStatus(" ")
        }
        if(key==1006)
            leftArrow = true;
        if(key==1007)
            rightArrow = true;
        return true;
    }