java JOptionPane如何禁用X?
如果用户单击右上角的X,我不希望发生任何事情。实现这一点的代码行是什么
Object [] options1 = {"Go Back", "Accept"};
int a3 =JOptionPane.showOptionDialog(null,"Mean arterial pressure restored.\nReassess all vitals STAT.", "Title", JOptionPane.YES_NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, options1[0]);
if(a3 == JOptionPane.CLOSED_OPTION)
{
//what should i put here? if user X out, I want no response (DO_NOTHING_ON_CLOSE)
}
if(a3 == JOptionPane.YES_OPTION)
{
// doing something else
}
if (a3 == JOptionPane.NO_OPTION)
{
//doing something else
}
我试过a3之类的。setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 但我得到一个错误int不能被解引用
# 1 楼答案
这段代码可能会起作用(您可以运行代码来测试它):
# 2 楼答案
那么这种极简主义的方法呢: