如何聚焦 JFrame? [英] How to focus a JFrame?

查看:32
本文介绍了如何聚焦 JFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个小游戏,其中一个 JFrame 保存主游戏,另一个 JFrame 显示分数.问题是,当我完成构建它们时,JFrame 的分数总是最终聚焦!我试过调用 scoreDisplay.toFront()、scoreDisplay.requestFocus(),甚至:

I am writing a small game, with one JFrame that holds the main game, and another JFrame that displays the score. the problem is, when I am done constructing them, the score JFrame always ends up focused! I have tried calling scoreDisplay.toFront(), scoreDisplay.requestFocus(), and even:

display.setState(JFrame.ICONIZED);
display.setState(JFrame.NORMAL);

有什么办法可以使这个工作?提前致谢,约翰·穆拉诺

Is there any way to make this work? Thanks in advance, john murano

推荐答案

有没有考虑将分数设置在与游戏框架相同的框架中?

Have you consider setting the score in the same frame as the game frame?

其他可能的(快速和肮脏的)选项是以相反的顺序创建它们,或者至少(如果分数取决于游戏)以相反的顺序显示它们.

Other possible ( quick and dirty ) option is to create them in reverse order, or at least ( if score depends on game ) display them in reverse order.

score.setVisible( true );
game.setVisible( true );

我的猜测是目前它们是:

My guess is that currently they are:

game.setVisible( true );
score.setVisible( true );

这篇关于如何聚焦 JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆