当我输入高分文本字段时,我的程序有时会冻结?

发布于 2024-11-24 02:21:57 字数 1077 浏览 2 评论 0原文

我正在制作一款与 swing 组件一起使用的游戏(仅用于提交高分),但有时当我输入内容时会冻结;我不知道为什么,而且很难调试。

因此,我必须

create class SubmitHighScore(ScreenManager, int forScore)
implement KeyListener

禁用 swing 来使用我创建的名为 NullRepaintManager 的类来绘制自身。我这样做是为了可以不闪烁地绘制

这是我填写的实现方法

@Override
public void keyTyped(KeyEvent e) {
    // TODO Auto-generated method stub

    //e.consume();
}

@Override
public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if (e.getKeyCode()==KeyEvent.VK_ENTER){
        highScore.addScore(new Score(highScoreTextField.getText(),score));
        exit.tap();
    }
    //e.consume();

}

@Override
public void keyReleased(KeyEvent e) {
    //filter High Score text. Only A-Z and a-z otherwhise will ignore
    highScoreTextField.setText(filter(highScoreTextField.getText()));
    //e.consume();
}

这是一个简单的名称,当玩家按 ENTER 键时将提交该名称,但有时会冻结。我尝试使用 setFocusTraversalKeysEnabled(false) 并调用 e.consume (这使得当我调用 Consumer 时我的文本字段未填满)

如何解决此问题?

还有其他方法可以提交高分吗?请注意,我用背景和框架装饰高分,因此它看起来就像另一个游戏。

I am making a game that work with swing components (only for submitting high scores) but sometimes when I type things freeze; I don't know why and it's hard to debug.

So, I had to do this

create class SubmitHighScore(ScreenManager, int forScore)
implement KeyListener

I disabled swing to draw itself with the class that I created, called NullRepaintManager. I did this so I can draw without flicker

This is the implemented method that I filled

@Override
public void keyTyped(KeyEvent e) {
    // TODO Auto-generated method stub

    //e.consume();
}

@Override
public void keyPressed(KeyEvent e) {
    // TODO Auto-generated method stub
    if (e.getKeyCode()==KeyEvent.VK_ENTER){
        highScore.addScore(new Score(highScoreTextField.getText(),score));
        exit.tap();
    }
    //e.consume();

}

@Override
public void keyReleased(KeyEvent e) {
    //filter High Score text. Only A-Z and a-z otherwhise will ignore
    highScoreTextField.setText(filter(highScoreTextField.getText()));
    //e.consume();
}

This is a simple name that will be submitted when a player presses the ENTER key, but it freezes sometimes. I have tried using setFocusTraversalKeysEnabled(false) and called e.consume (which makes my textfield not fill up when I called consume)

How do I fix this?

Is there another way to submit high scores? Note that I decorate high scores with bg and frame so it look just like another game.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文