如何关注JFrame? [英] How to focus a JFrame?

查看:102
本文介绍了如何关注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);

有没有办法让这项工作成功?
提前致谢,
john murano

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天全站免登陆