用于游戏场景的多个JFrame

用于游戏场景的多个JFrame

本文介绍了用于游戏场景的多个JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,标题的措词不正确.

I'm sorry if the title is worded a bit incorrectly.

我最近开始了一个新的Game项目,并考虑过在Java中使用多个 JButton的actionPerformed()方法中的问题,

To help clarify in my MainMenu UI inside an actionPerformed() method of Start Game JButton I have:

 class MainMenu extends JFrame implements ActionListener {
        ...
            public void actionPerformed(..){
            NarutoGame narutoGame = null;
                narutoGame = new NarutoGame(...);

            narutoGame.setVisible(true);//running in MainMenu EDT
            //set this panels containing frame (MainMenu) to not visible
            }
        ...
   MainMenu getInstance() {
        ...
   }
 }

在Battle JFrame中游戏结束时:

When the game is over in Battle JFrame:

class BattleField extends JFrame  {
    ...
    private void gameOver() {
        MainMenu.getInstance().setVisible(true);
        dispose();//dipsose of Battle JFrame
    }
    ...
}

推荐答案

以培养愿意的暂停怀疑和简单的游戏一样,游戏通常会以新颖的方式推动用户界面设计.实际上,多个框架的吸引力可能大于风险.除了在此处中引用的众所周知的问题之外,我还要添加.

To foster the willing suspension of disbelief, as well as for simple variety, games often push user interface design in novel ways. In practice, the appeal of multiple frames may not outweigh the risk. In addition to the well-known problems cited here, I would add the nightmare adduced here.

如果CardLayout不适当,则 Buttons 是一个简单的示例调用resetGame()中的removeAll().

If CardLayout is inappropriate, Buttons is an example that simply invokes removeAll() in resetGame().

这篇关于用于游戏场景的多个JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:38