本文介绍了JOptionPane的YES NO OPTION的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了一个JOptionPane的和是和否按钮。但是,任何按钮,单击它仍然存在。帮帮我!继承人的code:
INT dialogButton = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog(NULL,你确定吗?,警告,dialogButton);
如果(dialogButton == JOptionPane.YES_OPTION){
System.exit(0);
如果(dialogButton == JOptionPane.NO_OPTION){
删除(dialogButton);
}
}
解决方案
您应该真正从选项窗格拍摄效果:
dialogButton = JOptionPane.showConfirmDialog(NULL,你确定吗?,警告,dialogButton);
否则,它仍然设置为 JOptionPane.YES_NO_OPTION
。
清洁将是:
如果(JOptionPane.showConfirmDialog(NULL,你确定吗?,警告,
JOptionPane.YES_NO_OPTION)== JOptionPane.YES_OPTION){
// yes选项
}其他{
//别无选择
}
虽然,我不知道这是什么线,预计在发布code ++做的:删除(dialogButton);
有关更多细节和例子看看教程。
I got an JOptionPane and yes and no buttons. But, whichever button you click it still exists. HELP! Heres the code:
int dialogButton = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog (null, "Are you sure?","WARNING", dialogButton);
if(dialogButton == JOptionPane.YES_OPTION) {
System.exit(0);
if(dialogButton == JOptionPane.NO_OPTION) {
remove(dialogButton);
}
}
解决方案
You should actually take the result from the option pane:
dialogButton = JOptionPane.showConfirmDialog (null, "Are you sure?","WARNING", dialogButton);
Otherwise, it remains set to JOptionPane.YES_NO_OPTION
.
Cleaner would be:
if (JOptionPane.showConfirmDialog(null, "Are you sure?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
// yes option
} else {
// no option
}
Although, I'm not sure what this line is expected to do in the posted code: remove(dialogButton);
.
For more details and examples check out How to Make Dialogs tutorial.
这篇关于JOptionPane的YES NO OPTION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!