当我wait()
在以下代码中使用该方法时,它会抛出以下异常
Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException
代码如下:
private void newMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
newFileChooser = new JFileChooser();
int returnVal = newFileChooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
filename = newFileChooser.getSelectedFile();
JFrame mainFrame = NetSimApp.getApplication().getMainFrame();
networktype = new NetType(mainFrame);
networktype.setLocationRelativeTo(mainFrame);
NetSimApp.getApplication().show(networktype);
try {
this.wait();
} catch (InterruptedException ex) {
Logger.getLogger(NetSimView.class.getName()).log(Level.SEVERE, null, ex);
}
if (!NetType.validip) {
statusTextArea.append("File not created:Select Network Type.\n");
}
newNodeMenuItem.setEnabled(true);
} else {
newNodeMenuItem.setEnabled(false);
statusTextArea.append("File not created:Access cancelled by user.\n");
}
}
实际上我正在调用 jDialog 类的对象,我希望对话框对象应该首先完成,然后它应该通知上面给定的代码。我已经在那个类中指定了 notify() 。谁能告诉我是什么问题及其解决方案。-提前致谢