如何从JDialog中提取按下的按钮?

发布于 2024-12-11 18:38:02 字数 1031 浏览 0 评论 0原文

我在以下几行中使用 JOption C'tor 生成了一个 JDialog:

 Object[] options =
            {
        "Yes", "No (Exit to main menu)"
        };
        JOptionPane messagePane = new JOptionPane(i_StringMessage+"\nDo you want to begin another Net Game?", JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options);
        messagePane.setLocation(500, 1000);
        JDialog dialog = messagePane.createDialog(m_GameApplet.GetJpanelStartNetGame(), "Game over");
        m_GameApplet.GetJpanelStartNetGame().SetPopUpWindowReference(dialog);
        m_GameApplet.GetJpanelStartNetGame().GetPopUpWindowReference().setVisible(true);

我将 JDialog 设置为可见,但我想知道现在如何以类似的方式接收和解析用户单击的按钮使用这样的静态 JOption 函数:

int userChoice = JOptionPane.showOptionDialog(this, i_StringMessage+"\nDo you want to begin another Net Game?",
                "Game over", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);

如何关闭 JDialog,以及 dispose 函数的作用是什么?
谢谢

I've generated a JDialog with the use of JOption C'tor in the following lines:

 Object[] options =
            {
        "Yes", "No (Exit to main menu)"
        };
        JOptionPane messagePane = new JOptionPane(i_StringMessage+"\nDo you want to begin another Net Game?", JOptionPane.INFORMATION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options);
        messagePane.setLocation(500, 1000);
        JDialog dialog = messagePane.createDialog(m_GameApplet.GetJpanelStartNetGame(), "Game over");
        m_GameApplet.GetJpanelStartNetGame().SetPopUpWindowReference(dialog);
        m_GameApplet.GetJpanelStartNetGame().GetPopUpWindowReference().setVisible(true);

I set the JDialog to be visible, but I wonder how can I now receive and parse the button that the user has clicked on, in a similar way to using the static JOption functions like that:

int userChoice = JOptionPane.showOptionDialog(this, i_StringMessage+"\nDo you want to begin another Net Game?",
                "Game over", JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);

How can I close a JDialog, and what does dispose function excately do?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硬不硬你别怂 2024-12-18 18:38:02

请参阅以下链接中的“直接使用:”部分:

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html

您需要使用 getValue() 获取所选值代码>的JOptionPane 并进行相应的解析。

See the "Direct Use:" section in the link below:

http://download.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html

You will need to get the selected value using getValue() of JOptionPane and parse accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文