如何从JDialog中提取按下的按钮?
我在以下几行中使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅以下链接中的“直接使用:”部分:
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.