- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我设置了2个Jmenu项,一个是“新游戏”,另一个是“关于游戏”。但是,当我运行程序并按“新游戏”时,会显示“关于游戏”对话框,那么我该如何解决这个问题呢?
public Game() {
JMenuBar menuBar = new JMenuBar();
this.mainFrame.setJMenuBar(menuBar);
JMenu aMenu = new JMenu ("New Game");
menuBar.add(aMenu);
newMenuItem("New Game", aMenu, this);
JMenu bMenu = new JMenu("About");
menuBar.add(bMenu);
newMenuItem("About the game",bMenu,this);
}
public void aboutGame () {
final String AboutGameText =
" The game is about...";
JOptionPane.showMessageDialog(this.mainFrame, AboutGameText, "About the game", JOptionPane.PLAIN_MESSAGE);
}
public void actionPerformed(ActionEvent arg0) {
if (arg0.getActionCommand().equals("New Game")) Game();
if (arg0.getActionCommand().equals("About the game")); aboutGame();
}
最佳答案
在行
if (arg0.getActionCommand().equals("About the game")); aboutGame();
if 语句后有一个分号。本质上,这将 if 语句简化为没有主体的 if 语句。因此,jvm 将处理 true 或 false,丢弃结果,然后移至下一行,即 aboutGame()
行。如果删除它,问题就会消失。顺便说一句,省略大括号从来都不是一个好主意,即使在一行 if 语句中也是如此
if (arg0.getActionCommand().equals("About the game")) {
aboutGame();
}
关于java - JMenu反复显示showMessageDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50140570/
我有一个小心理障碍:我有一个 html 中的 javascript 函数,可以在按下某个键时写入键码。我已经将它连接到一个函数,该函数可以准确地告诉我按下了什么字符和键码(不包括在内)。 我的问题是如
我上网已经有一段时间了,现在正试图解决这个问题。可以找到正在发生的事情的视频: https://i.gyazo.com/59fc489b6099b513c41aedeed482b8d2.mp4 $(d
我有一个 Python 程序,其中一个函数导入另一个脚本并运行它。但是脚本仅在第一次函数被调用时运行。 def Open_Generator(事件): 导入密码生成器 有什么建议吗? *该函数在 tk
我正在尝试在 git 中创建两个包含二进制文件的分支 - 一个“开发”分支和一个“稳定”分支。在我想将它们“发布”到稳定分支之前,开发分支可以对这些文件进行一些更改(并且稳定分支已重命名这些文件,以防
我在 IBM BlueMix 中的 Node Red 应用程序反复崩溃 - 每小时一次 - 除了“exited with status: 1.”之外没有任何真正的错误消息 如何解决此问题? 是否有来自
我是一名优秀的程序员,十分优秀!