关于记事本关闭时的提示框~~
devoc 2006-12-26 02:35:28 做了一个类似于windows的记事本,其他差不多都做好了
就差当文本改动后关闭记事本弹出提示框的问题了
大体代码如下,能编译成功,但文本改动了关闭也没反应啊,,,,
/*----------看文本是否发生了变化------------*/
jtext.getDocument().addDocumentListener(new DocumentListener()
{
public void insertUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
public void removeUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
public void changedUpdate(DocumentEvent e)
{
wasChange=isChange;
isChange=true;
}
});
//"关闭"选项
JFileChooser chooser = new JFileChooser(".");
if(e.getSource().equals(exitFile))
{
if(isChange==false)
System.exit(0);
else
{
int decision=JOptionPane.showConfirmDialog(this,"文件已被改
变.\n"+"要保存文件么 ^0^","记事本",
JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);
if(decision == JOptionPane.YES_OPTION)
{
try
{
FileOutputStream out=new FileOutputStream
(chooser.getSelectedFile());
byte b[]=(text.getText()).getBytes();
out.write(b);
}
catch(FileNotFoundException filenoe)
{
JOptionPane.showMessageDialog(this,"保存文件错误",
"警 告",JOptionPane.ERROR_MESSAGE);
}
catch(IOException ieox)
{
}
}
else if (decision == JOptionPane.NO_OPTION)
System.exit(1);
else if (decision == JOptionPane.CANCEL_OPTION);
}
}