G_MESSAGE,null);
switch(option)
{
case JOptionPane.YES_OPTION:
saveFile();
break;
case JOptionPane.NO_OPTION:
open();
break;
}
}
}
private boolean isCurrentFileSaved()
{
if(stateBar.getText().equals("未修改"))
{
return false;
}
else {
return true;
}
}
private void open() {
// TODO Auto-generated method stub
JFileChooser fileChooser=new JFileChooser();
int option=fileChooser.showDialog(null,null);
if(option==JFileChooser.APPROVE_OPTION)
{
try{
BufferedReader buf=new BufferedReader(new FileReader(fileChooser.getSelectedFile()));
setTitle(fileChooser.getSelectedFile().toString());
textArea.setText("");
stateBar.setText("未修改");
// String lineSeparator=new System.getProperty("line.separator");
String text;
while((text=buf.readLine())!=null)
{
textArea.append(text);
// textArea.append(lineSeparator);
}
buf.close();
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null,e.toString(),"开启文件失败",JOptionPane.ERROR_MESSAGE);
}
}
}
private void saveFile() {
// TODO Auto-generated method
stub
File file=new File(getTitle());
if(!file.exists())
{
saveFileAs();
}
else{
try{
BufferedWriter buf=new BufferedWriter(
new FileWriter(file));
buf.write(textArea.getText());
buf.close();
stateBar.setText("未修改");
}
catch(IOException e)
{
JOptionPane.showMessageDialog(null, e.toString(),"写入文件失败",JOptionPane.ERROR_MESSAGE);
}
}
}
private void saveFileAs() {
// TODO Auto-generated method stub
JFileChooser fileChooser=new JFileChooser();
int option=fileChooser.showDialog(null, null);
if(option==JFileChooser.APPROVE_OPTION)
{
File file=fileChooser.getSelectedFile();
setTitle(file.toString());
try{
file.createNewFile(