高手来看看我这个"记事本"的另存为功能怎么没有真正实现
完整代码如下:
/**
* @(#)notepad.java
*
*
* @author
* @version 1.00 2007/4/18
*/
import java.awt.*;
import java.awt.Frame;
import java.awt.event.*;
import java.io.*;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.Image;
import java.lang.String;
import java.awt.Toolkit;
public class notepad {
public static void main (String[] args) {
final Frame f=new Frame( "记事本 ");
f.setBackground(Color.white);
f.setLocation(200,100);
f.setSize(600,600);
f.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
final TextArea ta=new TextArea(200,200);
f.add(ta);
MenuBar mb=new MenuBar();
Menu m1=new Menu( "文件 ");
Menu m2=new Menu( "编辑 ");
MenuItem mi1=new MenuItem( "新建 ");
MenuItem mi2=new MenuItem( "打开 ");
mi2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
FileDialog fd=new FileDialog(f, "打开文件 ",FileDialog.LOAD);
fd.show();
String strFile=fd.getDirectory()+fd.getFile();
if(strFile!=null)
{
try {
FileInputStream fis=new FileInputStream(strFile);
byte[] buf=new byte[10*1024];
int len=fis.read(buf);
ta.append(new String(buf,0,len));
fis.close();
}
catch (Exception ex) {
System.out.println(ex.toString());
}
}
}
}
);
MenuItem mi3=new MenuItem( "保存 ");
mi3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
try {
FileDialog fd2=new FileDialog(f, "保存 ",FileDialog.SAVE);
}
catch (Exception exc) {
System.out.println(exc.toString());
}
}
}
);
MenuItem mi4=new MenuItem( "退出 ");