我想在出现异常时发出警报,例如在代码中:
try { //the code here } catch(Exception e) { //show an alert dialog here }
我需要一个示例或代码片段.
试试这个:
JOptionPane.showMessageDialog(null, "My Goodness, this is so concise");
如果您静态导入JOptionPane.showMessageDialog,则进一步减少为
showMessageDialog(null, "This language just gets better and better!");
你可以用JOptionPane.showMessageDialog
与WARNING_MESSAGE
:
JOptionPane.showMessageDialog(yourFrame, "WARNING.", "Warning", JOptionPane.WARNING_MESSAGE);
有关如何在此处进行对话的更多信息.