在 Java Swing 中显示警报对话框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20349942/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 01:16:14 来源:igfitidea点击:
Showing an Alert Dialog in Java Swing
提问by Ved
I want to giving an alert when there is an exception, like in code:
我想在出现异常时发出警报,例如在代码中:
try
{
//the code here
}
catch(Exception e)
{
//show an alert dialog here
}
An example or a code snippet is what I need.
我需要一个示例或代码片段。
采纳答案by user2336315
回答by KethanKumar
try this:
尝试这个:
JOptionPane.showMessageDialog(null, "My Goodness, this is so concise");
If you statically import JOptionPane.showMessageDialog this further reduces to
如果您静态导入 JOptionPane.showMessageDialog 这将进一步减少到
showMessageDialog(null, "This language just gets better and better!");