当我输入高分文本字段时,我的程序有时会冻结?
我正在制作一款与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论