简体   繁体   English

如何清除 Java 小程序的状态文本?

[英]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.我正在使用小程序在 Java 中编写游戏 Breakout,我使用了一些showStatus("")行在小程序的窗口中说一些showStatus("")

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.如果按下向上箭头(键 1004),游戏就会开始,我希望状态文本消失。

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

The answer is very simple!答案很简单! Just by adding literally the showStatus(" ").只需在字面上添加 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM